Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,
I am new to C++, I have a server application in C++ in that i want to get the Linux machine time zone using C++. I am able to get the time zone in windows machine i want to zone id to do some functionality in my client application. I tried lot search not useful. Can any one help me to come out of it. Thanks in advance.
Posted
Comments
[no name] 11-May-14 8:37am    
Maybe this helps:
http://www.codeproject.com/Questions/745717/How-to-get-current-timezone-on-linux-in-Cplusplus

C++
#include <ctime>
#include <iostream>

int main(void)
{
    time_t rawtime;
    struct tm * ptm;
    time ( &rawtime );
    ptm = gmtime ( &rawtime );

    //const char *tm_zone; /*Timezone abbreviation*/
    std::cout << ptm->tm_zone;
    //output: "GMT" in my machine.

    return 0;
}


My linux box:
-------------
Linux jcasimiro-Mint 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

JAFC
 
Share this answer
 
Comments
Maciej Los 24-May-14 14:03pm    
Nice ;)
Maybe this helps:
How to get current timezone on linux in C++[^]
maybe...
 
Share this answer
 
v2
Comments
Maciej Los 24-May-14 14:03pm    
Looks good ;)
[no name] 24-May-14 15:30pm    
Thank you Maciej ;) Regards, Bruno

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