开发者

Python date formatting without space?

开发者 https://www.devze.com 2022-12-14 07:42 出处:网络
How to开发者_如何转开发 display the following without any space also could we substitute a separator instead of space?

How to开发者_如何转开发 display the following without any space also could we substitute a separator instead of space?

> log_time=datetime.datetime.now()
> print log_time
2009-12-16 16:10:03.558991


This works like a charm!

Without any separator

import datetime
datetime.datetime.now().strftime("%Y%m%d%H%M%S")

Using - as separator

import datetime
datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")

Using _ as separator

import datetime
datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")


Use datetime.date.strftime().

0

精彩评论

暂无评论...
验证码 换一张
取 消