Answer by Moobie for Convert python datetime to epoch with strftime
For an explicit timezone-independent solution, use the pytz library.import datetimeimport pytzpytz.utc.localize(datetime.datetime(2012,4,1,0,0), is_dst=False).timestamp()Output (float): 1333238400.0
View ArticleAnswer by SuperNova for Convert python datetime to epoch with strftime
In Python 3.7Return a datetime corresponding to a date_string in one of the formats emitted by date.isoformat() and datetime.isoformat(). Specifically, this function supports strings in the format(s)...
View ArticleAnswer by Marc Maxmeister for Convert python datetime to epoch with strftime
if you just need a timestamp in unix /epoch time, this one line works:created_timestamp = int((datetime.datetime.now() - datetime.datetime(1970,1,1)).total_seconds())>>>...
View ArticleAnswer by Luis Pollo for Convert python datetime to epoch with strftime
This works in Python 2 and 3:>>> import time>>> import calendar>>> calendar.timegm(time.gmtime())1504917998Just following the official...
View ArticleAnswer by Charles Plager for Convert python datetime to epoch with strftime
import timefrom datetime import datetimenow = datetime.now()# same as above except keeps microsecondstime.mktime(now.timetuple()) + now.microsecond * 1e-6(Sorry, it wouldn't let me comment on existing...
View ArticleAnswer by srossross for Convert python datetime to epoch with strftime
import timefrom datetime import datetimenow = datetime.now()time.mktime(now.timetuple())
View ArticleAnswer by jleahy for Convert python datetime to epoch with strftime
In Python 3.3+ you can use timestamp():>>> datetime.datetime(2012,4,1,0,0).timestamp()1333234800.0In Python 3.2 or earlier, you could do it explicitly:>>>...
View ArticleAnswer by Savir for Convert python datetime to epoch with strftime
I had serious issues with Timezones and such. The way Python handles all that happen to be pretty confusing (to me). Things seem to be working fine using the calendar module (see links 1, 2, 3 and...
View ArticleConvert python datetime to epoch with strftime
I have a time in UTC from which I want the number of seconds since epoch.I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an...
View Article
More Pages to Explore .....