k1k4ss0
k1k4ss0

Reputation: 87

Get systime from datetime

I got a variable with a timestamp in datetime format:

2022-02-10 11:37:43.253630

And I want theequivalent value in systime (for unix)

Upvotes: 1

Views: 143

Answers (1)

Mark Tolonen
Mark Tolonen

Reputation: 177685

I think you want:

>>> from datetime import datetime as dt
>>> dt.strptime('2022-02-10 11:37:43.253630','%Y-%m-%d %H:%M:%S.%f')
datetime.datetime(2022, 2, 10, 11, 37, 43, 253630)
>>> x = dt.strptime('2022-02-10 11:37:43.253630','%Y-%m-%d %H:%M:%S.%f')
>>> help(x.timestamp)
Help on built-in function timestamp:

timestamp(...) method of datetime.datetime instance
    Return POSIX timestamp as float.
>>> x.timestamp()
1644521863.25363

Upvotes: 1

Related Questions