0

How can I use the "datetime" class to get a different time zone than mine?
(for example gmt = 0 or utc+2)

Thanks!

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by iPanda
0

Here is an example ...

# show the time in a different time zone
# see also: http://worldtimezone.net/

import datetime as dt

now = dt.datetime.now()

# for instance Los Angeles California
# runs 8 hours behind GMT time
gmt_offset = -8
gmt = dt.timedelta(hours=gmt_offset)

print("Current L.A. time = %s" % now.time())
print("Current GMT time  = %s" % (now - gmt).time())

''' my output -->
Current L.A. time = 12:44:24.181000
Current GMT time  = 20:44:24.181000
'''

You might have to allow for daylight savings time.

Edited by vegaseat: dst

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.