由字串格式轉化為日期格式的函式為: datetime.datetime.strptime()
由日期格式轉化為字串格式的函式為: datetime.datetime.strftime()
# encoding: utf-8 import datetime day = datetime.datetime.strptime('2020-2-18 10:54:45', '%Y-%m-%d %H:%M:%S') print(day) print type(day) day = datetime.datetime.strftime(day, '%Y-%m-%d %H:%M:%S') print(day) print type(day)
root@tao:/var/www/html/python# python 3.py
2020-02-18 10:54:45
<type 'datetime.datetime'>
2020-02-18 10:54:45
<type 'str'>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/193110.html
標籤:Python
