Convert date and time to another

I have two datetime strings like this one '2010-08-31 04: 35: 50.176725' and '2010-09-05 04: 35: 50.176725'. now my question is how to count seconds between two dates. I used a temporary delta, but its return in an hour, a minute forms. I want it to be in seconds.

+3
source share
2 answers
import datetime as dt
import time

now=dt.datetime.now()

The era is defined as 1970-01-01 00:00:00 GMT. You can find the number of seconds between nowand Epoch as follows:

print(time.mktime(now.timetuple()))
# 1289565310.0

Or, if you want to find the number of seconds between two dt.datetime objects:

now2=dt.datetime(2010,11,12,12,0,0)

def timestamp(date):
    return time.mktime(date.timetuple())

print(timestamp(now2)-timestamp(now))
# 15890.0
+14
source

I assume you want to find the difference between two dates in seconds?

, timedelta ( datetime -). seconds .

0

Source: https://habr.com/ru/post/1774509/


All Articles