1

Does anyone know how to get the abbreviated timezone name in Windows?

I am using this code to get the time zone name but not getting the abbreviated timezone.

time(&ltime);
newtime = localtime(&ltime);
strftime(sDate, 80,"%a, %d %b %Y %H:%M:%S %Z", newtime);

Output: Fri, 16 Aug 2013 14:45:27 India Standard Time

Expected output Fri, 16 Aug 2013 14:45:27 IST

Thanks,

user2499879
  • 673
  • 3
  • 10
  • 16
  • http://social.msdn.microsoft.com/Forums/vstudio/en-US/f76b8164-a918-4b74-b6d0-b38590c0a537/how-to-control-strftime-z-format – doctorlove Aug 16 '13 at 11:42

2 Answers2

2

There is no universal standard for time zone abbreviations. You can review the list here, but even then there are some that are not listed or ambiguous.

For example, some people use HAST for Hawaii, while others use HST because they could care less about the Aleutian islands in Alaska (which is what the A is supposed to represent).

Also, values like CST could be "Central Standard Time" (USA), "China Standard Time", or "Cuba Standard Time". EST could be "Eastern Standard Time" (USA), or "Eastern Standard Time" (Australia).

I could go on all day. The point is, you should only use time zone abbreviations when showing time to a human, and only when there is some other implied context like location. If you want one for those scenarios, you will need some conditional logic in your application, any you need to be careful to avoid making the false assumption that an offset can be directly translated to a time zone or a single abbreviation.

You might be able to come up with an abbreviation for a full IANA/Olson time zone, but you will need a TZDB implementation - which is not native in C on Windows. For more details, see this question and answer.

There are a few specifications such as RFC822 that use time zone abbreviations, but they only define a small handful of them, and are mostly fixated on the USA. They tend not to be included on anything more modern or having global impact.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
0

The docs state %Z returns

"Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown"

so you'll be hard-pressed to get what you want using strftime

doctorlove
  • 18,872
  • 2
  • 46
  • 62