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?

Drux
  • 557
  • 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. – Chris Davies Dec 25 '17 at 23:42
  • @roaima The first (GMT/UTC). – Drux Dec 26 '17 at 02:24
  • 1
    @muru But date -u only mentioned (as answer) here. – Drux Dec 26 '17 at 03: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 Dec 26 '17 at 03:24

2 Answers2

61

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.

jimmij
  • 47,140
21

Use the following command:

TZ=GMT date

The same format:

TZ=GMT date +"%Y%m%d%H%M%S"
20171225194014
GAD3R
  • 66,769