Python - Get Timezone and Format

Hello,

I’m trying to use Python to get the current Timezone from datetime and time.
There are a lot of examples of using pytz but this doesn’t seem to be available for our ancient python version we are using inside Dynamo.

I’m looking to get a format similair to this.
06:00, CST: Central Standard Time (North America)
06:00, BIOT: British Indian Ocean Time
08:00, PST: Pacific Standard Time (North America)

I can get the current date and time fine using but not timezone in the above format.

`import datetime`
`import time`
`currentDate = datetime.date.today().strftime("%Y/%m/%d")`
`currentTime = datetime.datetime.now().strftime("%H:%M")`

Any suggestions of ways to get the above if we don’t have access to pytz? My last resort would be to create a list of all the available “string” formats and use and for loop and if statement to run through it all, but I think that’s way to messy and there must be an easier way.

Thanks,
Matt

Try this:

from time import gmtime, strftime
print strftime("%z", gmtime())

Source:

1 Like

One way to get the current UTC/GMT time offset is like so:

image

I’m sure you can derive the alternatives from it

1 Like

This kinda works.
It is based on the current computer config. But if the user travels, or if you try and manually change the timezone, it does not update (time does) but not timezone.

I also tried this which is similar.
currentTimeZone = time.tzname

https://bugs.python.org/issue17627

So both @Dimitar_Venkov and @jacob.small examples work, but if a user travels to different time zones, they must close down Revit and Re-open. For whatever reason, closing Dynamo doesn’t work if a user has to change time zones.

Thanks guys.
Matt