datetime模块练习
#_author:来童星#date:2019/12/6#1.获取当前日期import datetimeprint(datetime.date.today())# 2019-12-06#2.使用today和now获取当前日期和时间,时间精确到毫秒级print(datetime.datetime.today())# 2019-12-06 11:23:11.102894print(datetime.datetime.now())#2019-12-06 11:23:11.102893#3.使用strftime()格式化时间为标准格式#strftime可以将日期输出为我们想要的格式(要特别注意参数区分大小写),如:只输出日期print(datetime.datetime.now().strftime('%Y-%m-%d'))# 2019-12-06#如果输出当前日期和时间,精确到秒,设置日期时间参数即可print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))# 2019-12-06#如果输出当前日期和时间,星期,%A是星期全写的参数,%a是星期简写的参数print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S %A '))# 2019-12-06 11:33:11