Python日期时间格式化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012111465/article/details/83830663
from datetime import datetime

update_stan = '18-11-07 10:10:10'
type(update_stan )
# output: <type 'str'>
# 字符串转为日期时间格式
update_str = datetime.strptime(update_stan, '%y-%m-%d %H:%M:%S')
update_str 
# output: datetime.datetime(2018, 11, 7, 10, 10, 10)
# 时间格式化为指定格式
update_date = update_str.strftime('%Y-%m-%d %H:%M:%S')
update_date
# output: '2018-11-07 10:10:10'

猜你喜欢

转载自blog.csdn.net/u012111465/article/details/83830663