Quantcast
Channel: Convert python datetime to epoch with strftime - Stack Overflow
Browsing all 9 articles
Browse latest View live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer by srossross for Convert python datetime to epoch with strftime

import timefrom datetime import datetimenow = datetime.now()time.mktime(now.timetuple())

View Article

Answer 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 Article

Answer 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 Article


Convert 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

Browsing all 9 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>