python 日期輸出附帶毫秒


 

def get_time_stamp(ct):
    local_time = time.localtime(ct)
    data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
   data_secs
= (ct - int(ct)) * 1000 time_stamp = "%s:%03d" % (data_head, data_secs) return time_stamp
print(get_time_stamp(1546244983.3656037))

輸出

2018-12-31 16:30:05:069

 

 

或者

import datetime
 
print(datetime.datetime.now()) 
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S:%f'))
print(datetime.datetime.now().strftime('%Y%m%d%H%M%S%f'))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM