8

This question already has an answer here:

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?

marked as duplicate by muru, Jesse_b, G-Man, EightBitTony, roaima Dec 26 '17 at 11:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

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.

9

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 or ask your own question.