Convert to UTC Timestamp

前端 未结 4 1298
遥遥无期
遥遥无期 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 01:02

    You probably want one of these two:

    import time
    import datetime
    
    from email.Utils import formatdate
    
    rightnow = time.time()
    
    utc = datetime.datetime.utcfromtimestamp(rightnow)
    print utc
    
    print formatdate(rightnow) 
    

    The two outputs look like this

    2009-10-20 14:46:52.725000
    Tue, 20 Oct 2009 14:46:52 -0000
    

提交回复
热议问题