python 日期与字符串之间的转换

1.str转换为datetime

>>> from datetime import datetime
>>> cday = datetime.strptime('2015-6-1 18:19:59', '%Y-%m-%d %H:%M:%S')
>>> print(cday)
2015-06-01 18:19:59

2.datetime转换为str

>>> from datetime import datetime
>>> now = datetime.now()
>>> print(now.strftime('%a, %b %d %H:%M'))
Mon, May 05 16:28

 

 

posted @ 2020-04-17 11:20  pple  阅读(633)  评论(0编辑  收藏  举报
以终为始,你期待的那天不会太遥远。