"""
datetime模块
"""
from datetime import datetime, timedelta
# 1,获取本地时间
print(datetime.now()) # 2020-03-02 11:27:14.453974
print(datetime.today()) # 2020-03-02 11:27:35.061829
# 2,获取当前世界时间
print(datetime.utcnow()) # 2020-03-02 03:28:13.927695
# 3,用指定日期时间创建datetime
print(datetime(2020, 5, 23))
# 4,字符串转换成datetime类型
a = datetime.strptime('2020-01-01 12:23:56', '%Y-%m-%d %H:%M:%S')
print(a, type(a))
# 5,datetime类型转换成字符串
today = datetime.now()
print(today.strftime('%Y-%m-%d %H:%M:%S'))
# 6,时间差
print('timedelta', timedelta(days=365))
bir = datetime.strptime('1993-08-21', '%Y-%m-%d')
print('bir', bir)
age = datetime.now() - bir
print('age', age, type(age))
# 补充:
m = datetime.now()
print(m.strftime('今天是%Y年%m月%d日'))
print(m.strftime('今天是这周的第%w天'))
print(m.strftime('今天是今年的第%j天'))
print(m.strftime('今周是今年的第%W周'))
print(m.strftime('今天是当月的第%d天'))