We have a server that runs in GMT. I need to write a Python script that determines whether it will currently (at this very second) Daylight Savings Time (DST) in Los Angeles, California. How can i do this? I took a look at pytz and time, but I can't figure it out. I understand that I could create some logic, such as comparing the current time in LA with GMT, but it would be much cleaner if I could use the standard library.
thank
Edit: Here is an example code that sets up the time zone:
from pytz import timezone import pytz from datetime import datetime, timedelta tz = timezone('America/Los_Angeles')
Edit: Here is a piece of code that will work. This is not elegant, so I ask if there is a library or something that has been done for this. Maybe like the function is_dst ().
utc = timezone("UTC") now = utc.localize(datetime.utcnow()) los_angeles_tz = timezone('America/Los_Angeles') los_angeles_time = now.astimezone(los_angeles_tz) delta = los_angeles_time.utcoffset() dstDelta = timedelta(hours=-8) is_dst = (delta == dstDelta)
python timezone time dst pytz
Joey Mason Nov 04 '13 at 18:39 2013-11-04 18:39
source share