time difference to UTC at your mac

Posted on
Sun Jun 28, 2015 11:38 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

time difference to UTC at your mac

If you need to know your time delta in seconds to UTC at the location of your MAC in your plugin: ( e.g. gnuplot time() is in UTC but seconds are not from epoch but from millennium ..)

Code: Select all
import time
import datetime
t=time.time()
timeDeltaToUTC=  (int(time.mktime(datetime.datetime.utcfromtimestamp(t+10).timetuple()) -t)/100)*100

for Dallas this is right now: timeDeltaToUTC = 18000 .. that changes with Daylight savings and regular time ..

The raw difference is not 18,000 as expected but 17999.01 ... 17999.79 (*) Thats why we add 10 and set the seconds to 00 with /100*100

there is probably a more elegant way but I have not found one..

Karl

(*) the 17999.xx seconds varies by +-0.x every time I call it. Looks like it gets some info in "utcfromtimestamp" from the internet?

Posted on
Sat Dec 05, 2015 6:47 am
DaveL17 offline
User avatar
Posts: 6758
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: time difference to UTC at your mac

Brilliant Karl, thanks. Saved me a ton of ...ahem... time. :D

My use case:
Code: Select all
import time
import datetime

t   = time.time()
utc = "2015-12-05T12:27:40Z"

time_delta_to_utc = (int(time.mktime(datetime.datetime.utcfromtimestamp(t + 10).timetuple()) - t) / 100) * 100
utc_obj           = datetime.datetime.strptime(utc,'%Y-%m-%dT%H:%M:%SZ')
local_time        = utc_obj - datetime.timedelta(seconds = time_delta_to_utc)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests