The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Implement daylight saving. masquerer AIX 1 05-15-2008 04:27 AM
Technical Note: Oracle Database Daylight Saving Time Update Guide iBot Oracle Updates (RSS) 0 04-06-2008 02:10 AM
Daylight Saving Time patch test dangral AIX 1 02-06-2007 09:17 AM
disable daylight saving ppass SUN Solaris 1 03-20-2006 07:57 AM
Timestamp - confusion with daylight saving time softmachine UNIX for Dummies Questions & Answers 1 05-14-2005 06:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-2008
Registered User
 

Join Date: May 2008
Posts: 3
Stumble this Post!
How can I find my current Daylight Saving offset?

Hello all,

I'm having a problem where a script needs to calculate GMT time given local time. For 6 months, that's easy. The other 6 months, it's not, as I have to add an extra hour to allow for Daylight Saving. At the moment, I manually add and remove an offset but, for obvious reasons, I'd prefer to automate this.

I was surprised that I couldn't find much discussion on this. What I'm looking for is some way to determine what the current local offset from GMT is. There is talk of an environment variable, $TZ, that includes information on the application of the summer time shift, but I cannot see this variable anywhere on my RHEL or Ubuntu machines.

So, is there a nice easy way to work out my current offset and therefore modify the size of the GMT shift I need. I'm thinking of using a cron, triggered at 0400 six months a year, to create $TZ or similar, but that would be ugly and just plain wrong for up to a day if I need to reboot during the summer!

Thanks!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-03-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,614
Stumble this Post!
date +%Z and variants should work on Linux. See also man tzset for some relevant discussion, and /etc/timezone for (a textual representation of) the system time zone.
Reply With Quote
  #3 (permalink)  
Old 06-03-2008
Registered User
 

Join Date: May 2008
Posts: 3
Stumble this Post!
No tzset is natively available, I'm afraid - that was somthing I came across earlier. Also, the /etc/timezones is good but doesn't include Daylight Saving information, only the time zone.

However, the date +%Z looks like a winner! It currently returns BST, which is correct (British Summer Time), and so presumably will switch to GMT in the winter. I just need to make my script run this and then compare the output to one of these two strings, adjusting the offset accordingly.

Pretty mush exactly what I was looking for! Cheers era!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, ubuntu

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0