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!

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.

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!