Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Currently i am using Strftime to get the timezone of my machine in windows. But in linux it gives only short timezone string like (IST) but i need (Indian standard time). In windows the same api give the long timezone string.

Below is the code i am using for both linux and windows.
strftime( buff, sizeof buff, "%Z" , &tnow );

Thanks in advance.
Posted

You need to use the tzfile and tzset[^] functions to find the name.
 
Share this answer
 
Comments
Andreas Gieriet 18-Mar-14 5:49am    
My 5!
Cheers
Andi
Richard MacCutchan 18-Mar-14 6:34am    
Thanks; another 5 for knowing how to use Google. :)
Andreas Gieriet 18-Mar-14 7:07am    
Are you a "Google Expert"? ;-) As soon as you know more than the average person, you are an "expert" :-)
Somehow I understand that people seek for advise since there is so much crap on certain topics on the internet - and sometimes it's plain lazyness of the poster to not search the internet himself... :-(
Cheers
Andi
Richard MacCutchan 18-Mar-14 7:21am    
I did have a slight advantage with this question, in that I have worked on Unix/Linux development in the past. However, the fact remains, that many "developers" still seem incapable of doing the most basic research for themselves.
Andreas Gieriet 18-Mar-14 9:12am    
Yeah, I have a similar background - started in the late 80ies and during the 90ies on some Unix (SunOS, Solaris, Ultrix, AIX, HPUX, SCO Unix, etc.) and others like VAX/VMS, AEGIS, DASIX, ..., Pascal/C/C++. That was before the WWW times - usenet was the way to communicate ideas and questions - and books were an invaluable source of information. Unbelievable, how it worked! But sometimes, I think - without becomming nostalgic - that it would help if things would be "slower" sometimes, so every body had time to digest the acquired information and not only seeking for the quick effect.
Cheers
Andi
I don't think there is a way in the linux system libraries to get that since the underlying libraries use the abbreviated forms only and the long forms are likely not available anywhere.

However, the ICU library does have the requisite methods and many more. It is installed by default on most modern linux distros (you will need libicu-dev or equivalent to compile): http://userguide.icu-project.org/datetime/timezone[^]

Sample code:

C++
#include 
#include <iostream>

using namespace U_ICU_NAMESPACE;

  TimeZone* tz = TimeZone::createDefault();
  UnicodeString us;
  std::string s;
  tz->getDisplayName(us);
  us.toUTF8String(s);
  std::cout << "Current timezone: " << s << '\n';
  delete tz;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900