开发者

Python date formatting without 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜