Converting datetime to POSIX time

后端 未结 6 1911
忘了有多久
忘了有多久 2021-01-31 02:14

How do I convert a datetime or date object into a POSIX timestamp in python? There are methods to create a datetime object out of a timestamp, but I don\'t seem to find any obv

6条回答
  •  逝去的感伤
    2021-01-31 02:37

    Best conversion from posix/epoch to datetime timestamp and the reverse:

    this_time = datetime.datetime.utcnow() # datetime.datetime type
    epoch_time = this_time.timestamp()      # posix time or epoch time
    this_time = datetime.datetime.fromtimestamp(epoch_time)
    

提交回复
热议问题