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()
.
精彩评论