How can I use the "datetime" class to get a different time zone than mine?
(for example gmt = 0 or utc+2)
Thanks!
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.
Thanks!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.