python-small-examples

@author jackzhenguo
@desc 
@date 2019/10/15

115 获取当前时间

from datetime import date, datetime
from time import localtime, strftime

today_date = date.today()
print(today_date)  # 2019-12-22

today_time = datetime.today()
print(today_time)  # 2019-12-22 18:02:33.398894

local_time = localtime()
print(strftime("%Y-%m-%d %H:%M:%S", local_time))  # 转化为定制的格式 2019-12-22 18:13:41
[上一个例子](/python-small-examples/md/114.html) [下一个例子](/python-small-examples/md/116.html)