Using frappe.utils.data.nowtime() returns the local time, as it should. I’m looking for a clean way to return UTC without hard coding the timezone.
frappe.utils.data.get_time_zone() returns a string - America/ New_York in my case.
Suggestions welcome.
I think python datetime and timedelta objects have methods to do the conversion from local time to UTC.
https://docs.python.org/2/library/datetime.html
Hope it helps.
MCD-50
March 15, 2017, 5:42am
3
Try this
import datetime
import dateutil.tz
utcdate = datetime.datetime.now(dateutil.tz.tzutc())
Thanks @MCD-50 and @littlehera ! I got it working using datetime.datetime.utcnow(). Unfortunately another RTFM moment for me, I was handling the import wrong and thought there was a conflict with the frappe tools.
3 Likes
Well, we’ve all been there at least once in our lives. Congrats!
For anyone stumbling on this now, on v15 you can just use:
frappe.utils.get_datetime_in_timezone("UTC")