LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-30-2012, 03:10 AM   #1
culin
Member
 
Registered: Sep 2006
Distribution: Fedora Core 10
Posts: 254

Rep: Reputation: 32
Regarding time zones..


Hi all ,

How can i read the timezone information from a c code ?

Eg:

time_t clock = time(NULL);
printf("Current time is %s\n", ctime(&clock));

The above code displays the calender time. But it wont show the timezone information. Where as the date command output from the command line shows it as IST. So, from where the date command is reading this information ? or how can i write a piece of C code as above to get the timezone information ? similar to date command output.

Cheers,
Naren
 
Old 08-30-2012, 04:19 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
http://www.cplusplus.com/reference/c...time/strftime/ should help. There's an example at the bottom, you just need to change the format string to get the timezone

Hope this helps,
 
Old 08-31-2012, 01:34 AM   #3
culin
Member
 
Registered: Sep 2006
Distribution: Fedora Core 10
Posts: 254

Original Poster
Rep: Reputation: 32
Cooooool !!! Snark1994... Thanks a lot for the info but is there a way to tell how or from where the strftime function reads this timezone info ?

Last edited by culin; 08-31-2012 at 01:36 AM.
 
Old 09-01-2012, 09:06 AM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
From the tm struct you pass to it

As you see in the code sample, you use time() to get the current time (in seconds from the epoch, IIRC) and you pass this to localtime() which then fills the tm struct appropriately.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE 4 bug? Time Zones alan_ri Linux - Desktop 3 11-23-2010 07:33 PM
date command with different time zones lothario Linux - Software 4 12-19-2007 04:47 PM
Kontact Groupware Time Zones Off jonwatson Linux - Software 0 06-20-2006 05:03 PM
desktop app: two time zones at once? TokyoYank Linux - Software 2 06-02-2006 04:58 AM
Time Zones in Linux skaa Linux - Software 5 06-29-2004 10:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration