1. 程式人生 > >Python日期時間格式化

Python日期時間格式化

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'