Convert to UTC Timestamp

前端 未结 4 1294
遥遥无期
遥遥无期 2021-01-08 00:09
//parses some string into that format.
datetime1 = datetime.strptime(somestring, \"%Y-%m-%dT%H:%M:%S\")

//gets the seconds from the above date.
timestamp1 = time.mk         


        
4条回答
  •  抹茶落季
    2021-01-08 00:46

    datetime.utcfromtimestamp is probably what you're looking for:

    >>> timestamp1 = time.mktime(datetime.now().timetuple())
    >>> timestamp1
    1256049553.0
    >>> datetime.utcfromtimestamp(timestamp1)
    datetime.datetime(2009, 10, 20, 14, 39, 13)
    

提交回复
热议问题