41

When I run date +"%Y%m%d%H%M%S" I receive 20171225203309 here in CET time zone.

Can I use date to obtain a the current time in the same format, but for timezone GMT?

4
  • If you're in CET (CEST) do you really want GMT/UTC or do you want the UK/Portugal WET (WEST) timezone? UTC/GMT never changes but WET (WEST) jumps twice a year like your own timezone. Commented Dec 25, 2017 at 23:42
  • @roaima The first (GMT/UTC).
    – Drux
    Commented Dec 26, 2017 at 2:24
  • 1
    @muru But date -u only mentioned (as answer) here.
    – Drux
    Commented Dec 26, 2017 at 3:20
  • @Drux special case only for UTC. The general way for using another timezone is the TZ environment variable. OP of that question even mentions this: "Looking through man date I see that I can have the time output as UTC"
    – muru
    Commented Dec 26, 2017 at 3:24

2 Answers 2

64

You can use date -u (universal time) which is equivalent to GMT.

Quoting date manual:

‘-u’ ‘--utc’ ‘--universal’

Use Universal Time by operating as if the ‘TZ’ environment variable were set to the string ‘UTC0’. UTC stands for Coordinated Universal Time, established in 1960. Universal Time is often called “Greenwich Mean Time” (GMT) for historical reasons. Typically, systems ignore leap seconds and thus implement an approximation to UTC rather than true UTC.

0
21

Use the following command:

TZ=GMT date

The same format:

TZ=GMT date +"%Y%m%d%H%M%S"
20171225194014

Not the answer you're looking for? Browse other questions tagged .