Python3 日期时间格式化(带毫秒)

import datetime
print(time.strftime("%Y%m%d%H%M%S", time.localtime()))  # 20210705113312
print(datetime.datetime.now())  # 2021-07-05 11:33:12.340230
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f'))  #2021-07-05 11:33:12.340230
print(datetime.datetime.now().strftime('%Y%m%d%H%M%S%f'))  # 20210705113312340230

返回结果
20210705113312
2021-07-05 11:33:12.340230
2021-07-05 11:33:12.340230
20210705113312340230

posted @ 2021-07-05 11:35  莫贞俊晗  阅读(4922)  评论(1编辑  收藏  举报