python的datetime转换为unix时间戳

 

将python的datetime转换为unix时间戳

import time

import datetime

 

dtime = datetime.datetime.now()

ans_time = time.mktime(dtime.timetuple())

 

将unix时间戳转换为python的datetime

 

import datetime

 

unix_ts = 1439111214.0

time = datetime.datetime.fromtimestamp(unix_ts)

 

将python的datetime转换为unix时间戳

  1.  
    import time
  2.  
    import datetime
  3.  
     
  4.  
    dtime = datetime.datetime.now()
  5.  
    ans_time = time.mktime(dtime.timetuple())

将unix时间戳转换为python的datetime

  1.  
    import datetime
  2.  
     
  3.  
    unix_ts =1439111214.0
  4.  
    time = datetime.datetime.fromtimestamp(unix_ts)
posted @ 2020-10-23 17:39  muyue123  阅读(1102)  评论(0编辑  收藏  举报