Convert UTC/GMT time to local time

For strings such as 2012-09-19 01:27:30.000, DateTime.Parse cannot tell what time zone the date and time are from. DateTime has a Kind property, which can have one of three time zone options: Unspecified Local Utc NOTE If you are wishing to represent a date/time other than UTC or your local time zone, then you should … Read more

Converting datetime.date to UTC timestamp in Python

If d = date(2011, 1, 1) is in UTC: >>> from datetime import datetime, date >>> import calendar >>> timestamp1 = calendar.timegm(d.timetuple()) >>> datetime.utcfromtimestamp(timestamp1) datetime.datetime(2011, 1, 1, 0, 0) If d is in local timezone: >>> import time >>> timestamp2 = time.mktime(d.timetuple()) # DO NOT USE IT WITH UTC DATE >>> datetime.fromtimestamp(timestamp2) datetime.datetime(2011, 1, 1, … Read more