美文网首页
python 字符串和时间格式(datetime)相互转换

python 字符串和时间格式(datetime)相互转换

作者: 刘东青_6f21 | 来源:发表于2019-03-21 17:04 被阅读0次

str转时间格式:
dd = '2019-03-17 11:00:00'
In [21]: dd = datetime.strptime(dd, "%Y-%m-%d %H:%M:%S")

In [22]: dd
Out[22]: datetime.datetime(2019, 3, 17, 11, 0)
时间格式转str:
In [28]: dc = dd.strftime("%Y-%m-%d %H:%M:%S")

In [29]: dc
Out[29]: '2019-03-17 11:00:00'

In [30]: type(dc)
Out[30]: str

相关文章

网友评论

      本文标题:python 字符串和时间格式(datetime)相互转换

      本文链接:https://www.haomeiwen.com/subject/iyecvqtx.html