Get the current time in UTC
Print the current wall-clock time in UTC (not local time) — essential for log correlation across machines and any DST-safe scheduling logic.
How to get the current time in utc in each shell
date -u`-u` (or `--utc` on GNU) forces UTC regardless of `$TZ`. Custom format: `date -u +"%Y-%m-%d %H:%M:%S UTC"`. Equivalent: `TZ=UTC date` — useful when piping through tools that ignore `-u`.
date -udate -u(Get-Date).ToUniversalTime()`Get-Date` returns LOCAL time by default — `.ToUniversalTime()` converts. Modern equivalent: `[DateTime]::UtcNow` (pwsh-native, no conversion). For seconds-since-epoch: `[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()`.
powershell -NoProfile -Command "[DateTime]::UtcNow"cmd has NO UTC primitive. `%date%`/`%time%` always reflect LOCAL time with no timezone marker — shipping these into logs across servers in different zones produces unreconcilable timelines.
Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.
Gotchas & notes
- Unix epoch (`date +%s`) is ALWAYS UTC — it counts seconds since `1970-01-01T00:00:00Z` regardless of the machine's local timezone setting. This is why log lines that record epoch are correlatable across servers without timezone metadata; lines that record `%H:%M:%S` (local) without a zone marker are NOT. Rule of thumb: if your log line lacks a `Z`/`+HH:MM` suffix, you don't know what zone it's in — and "production server in Frankfurt" vs "dev laptop in PST" is an 8-hour gap that hides hours-long incidents.
- pwsh `Get-Date` returns local time + `Kind=Local`. `(Get-Date).ToUniversalTime()` returns the same instant + `Kind=Utc`. `[DateTime]::UtcNow` returns UTC directly + `Kind=Utc`. Be aware: `[DateTime]::Now` returns LOCAL — easy confusion. The `Kind` property silently disappears across many serializers (JSON, CSV, Excel) — `[DateTimeOffset]::UtcNow` is safer because it serializes with an explicit `+00:00` and survives round-trips. Prefer `[DateTimeOffset]` over `[DateTime]` for any value that crosses a process boundary.
- macOS / BSD `date -u` works identically to GNU. The portable trick when scripts shell out to non-date tools that respect `$TZ`: `TZ=UTC ./my_script.sh` — every `date`, `find -printf %T`, `ls -l`, and tar listing inside that subshell reports UTC. Setting `TZ=UTC` globally on a Linux server (`/etc/timezone` → `Etc/UTC`) eliminates a whole class of "logs disagree with monitoring" incidents — most cloud providers ship images with `UTC` as the default; if you find yourself debugging timezone drift, check this first.
- cmd inherits the Windows control-panel timezone — no `-u`-equivalent flag exists for `%date%`/`%time%`. The robust path is `powershell -NoProfile -Command "(Get-Date).ToUniversalTime()"` or `wmic OS Get LocalDateTime` (which still returns LOCAL despite the name — confusing). Don't parse `%date%` for cross-server scripts: the format depends on Region settings (US `MM/DD/YYYY` vs EU `DD/MM/YYYY` vs ISO `YYYY-MM-DD`), and you can't programmatically detect which without first reading `HKCU\Control Panel\International\sShortDate` — at which point you should just shell out to pwsh.
Related commands
Related tasks
- Format the current date as ISO 8601— Emit `YYYY-MM-DDTHH:MM:SS±HH:MM` (or the UTC `…Z` form) — the format every machine-readable log, JSON API, and database column should agree on.
- Get the current timestamp— Print the current date / time as either a Unix epoch (seconds since 1970-01-01 UTC) or an ISO 8601 string — for log lines, filenames, expiry calculations, and HTTP `Date` headers.
- Convert a Unix epoch to a human-readable date— Render a Unix-epoch integer (e.g. `1747396980`) as a readable date — for log inspection, file-metadata audits, and translating database timestamps.