177

I have this timestamp value being return by a web service "2014-09-12T19:34:29Z"

I know that it means timezone, but what exactly does it mean?

And I am trying to mock this web service, so is there a way to generate this timestamp using strftime in python?

Sorry if this is painfully obvious, but Google was not very helpful and neither was the strftime() reference page.

I am currently using this :

x.strftime("%Y-%m-%dT%H:%M:%S%Z")
'2015-03-26T10:58:51'
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
roymustang86
  • 8,054
  • 22
  • 70
  • 101

1 Answers1

235

The T doesn't really stand for anything. It is just the separator that the ISO 8601 combined date-time format requires. You can read it as an abbreviation for Time.

The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).

Both characters are just static letters in the format, which is why they are not documented by the datetime.strftime() method. You could have used Q or M or Monty Python and the method would have returned them unchanged as well; the method only looks for patterns starting with % to replace those with information from the datetime object.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks, I was able to find a solution via the ISO time to string question http://stackoverflow.com/questions/127803/how-to-parse-iso-formatted-date-in-python . What is Q or M ? – roymustang86 Mar 26 '15 at 15:15
  • @roymustang86: `Q` and `M` are just random static characters. The point being that they are not `%Y` or any of the other *formatting characters*. – Martijn Pieters Mar 26 '15 at 15:16
  • 15
    The `Z` actually stands for [Zulu](http://www.timeanddate.com/time/zones/z), which is the "name" of UTC0. It sounds weird but every time zone has its respective name. – TomCho Mar 26 '15 at 18:03
  • 35
    @TomCho: no, `Zulu` is the NATO phonetic alphabet name for `Z`, and it is used because the timezone *is* timezone Zero. See the Wikipedia link I included in the answer: *UTC time is also known as "Zulu" time, since "Zulu" is the ICAO spelling alphabet code word for "Z".* – Martijn Pieters Mar 26 '15 at 18:04
  • 5
    @TomCho: looks like TimeAndDate has that backwards; `Z` came before `Zulu`, I'd say. http://en.wikipedia.org/wiki/List_of_military_time_zones is interesting but doesn't give any historical justification for Z being used for the zero-offset-timezone, only that `Z` is thus named `Zulu`. – Martijn Pieters Mar 26 '15 at 18:10
  • 1
    +1 True, I agree with you. It's weird that they don't use the letter `J` in the military zones. Maybe because of the different pronunciation in idioms like german, or finnish? Anyway thanks for clearing things out. – TomCho Mar 26 '15 at 18:21
  • 5
    @TomCho: [`Z` is used for `+0000` (GMT at the time) since 1950s](http://en.wikipedia.org/wiki/Nautical_time) (before UTC even existed). As I understand `Z` is just a letter (you could use a *mnemonic* `Zero` and/or pronounce it as `Zulu` (from the widely used spelling alphabet) – jfs Mar 26 '15 at 20:06
  • "The Z stands for the “zero meridian”, which goes through Greenwich in London, and it is also commonly used in radio communication where it is pronounced “Zulu” (the word for Z in the international radio alphabet). Universal Time (sometimes also called “Zulu Time”) was called Greenwich Mean Time (GMT) before 1972" (from [here](https://www.cl.cam.ac.uk/~mgk25/iso-time.html)) – 681234 Nov 10 '18 at 10:28
  • I was more curt than was necessary. The Cambridge University link is interesting but just a summary, not an authoritative reference. The author could even have misspoken, actually having meant *the zero timezone*. I rather stick to Wikipedia and leave research and discussion on the finer details to the WP editors. – Martijn Pieters Nov 10 '18 at 16:30
  • Possible to know what is the time zone? For example, I have a time value `2019-04-10T07:19:44+00:00`, I only know this is from USA, but not sure USA which zone. Thus, I cant know what is the exact time in Asia. I need to time to check log. – Panadol Chong Apr 15 '19 at 03:14
  • 1
    @PanadolChong: no, that's not a USA timezone. The `+00:00` part at the end is the timezone offset, so you have a UTC timestamp. – Martijn Pieters Apr 15 '19 at 17:41