tags:

views:

1162

answers:

3

What is the simplest way to get the machine's time zone as a positive or negative UTC offset, preferably using some time of shell command?

A: 

I figure that if worse comes to worse I can just send a request to an NTP server and take the difference of it and the current local time, but that seems kind of wasteful if the system knows its offset.

+2  A: 

For all Unix-ish operating systems, when using the GNU date command:

date +%z

Example, for Eastern European Time (my timezone):

[moocha@helium ~]$ date +%z
+0200
Mihai Limbășan
+1  A: 

If what you want is the non-summer/daylight-savings offset, you'd have to do something like:

date -d 'Jan 1' +%z

(or Jul in the southern hemisphere). This works with date from GNU coreutils, anyway.

Shockingly enough, I don't see any way to get the tm_isdst flag from date.

ysth