How to obtain GMT offset?

John Machin sjmachin at lexicon.net
Tue Aug 16 00:04:09 EDT 2005


new pip wrote:
> I'm using Windows os. If the current system date time is '28 Jun 2001
> 14:17:15 +0700', how can I obtain the value '+0700' using python?


If the current system date is in 2001, obtaining "GMT offset" is the 
least of your concerns :-)

Have you read the section on the time module in the Python manual?
If so, what didn't you understand?

One or more of the following might assist:

 >>> import time
 >>> time.gmtime(), time.localtime()
((2005, 8, 16, 3, 59, 3, 1, 228, 0), (2005, 8, 16, 13, 59, 3, 1, 228, 0))
 >>> time.timezone
-36000
 >>>

Looks like it's '-1000' (hours) for me at the moment. Daylight saving 
saving isn't operating here at the moment, so I can't tell whether that 
makes a difference. I haven't tried to understand the bits about DST in 
the manual, but maybe you should.


HTH,
John



More information about the Python-list mailing list