标签:ber date ftime mat time style 指定 form 输出
from datetime import datetime >>> datetime.now() datetime.datetime(2017, 9, 30, 17, 42, 32, 8337) >>> datetime.utcnow() datetime.datetime(2017, 9, 30, 9, 42, 47, 159508)
t=datetime(2017, 5, 23, 12, 20) >>> t datetime.datetime(2017, 5, 23, 12, 20)
将以下字符串转换成datetime类型:
>>> datetime.strptime(‘2017/9/30‘,‘%Y/%m/%d‘) datetime.datetime(2017, 9, 30, 0, 0) >>> datetime.strptime(‘2017年9月30日星期六‘,‘%Y年%m月%d日星期六‘) datetime.datetime(2017, 9, 30, 0, 0) >>> datetime.strptime(‘2017年9月30日星期六8时42分24秒‘,‘%Y年%m月%d日星期六%H时%M分%S秒‘) datetime.datetime(2017, 9, 30, 8, 42, 24) >>> datetime.strptime(‘9/30/2017‘,‘%m/%d/%Y‘) datetime.datetime(2017, 9, 30, 0, 0) >>> datetime.strptime(‘9/30/2017 8:42:50‘,‘%m/%d/%Y %H:%M:%S‘) datetime.datetime(2017, 9, 30, 8, 42, 50)
from datetime import datetime t=datetime(2017,9,28,10,3,43) print(t.strftime(‘%Y年%m月%d日星期4,%H时%M分%S秒‘)) s2=datetime(2017,9,30,9,22,17) print(s.strftime(‘%A,%B %d,%Y‘)) print(s.strftime(‘%m/%d/%Y %H:%M:%S AM‘)) print(s.strftime(‘%B %d,%Y‘))
from datetime import datetime time=datetime.now() print(‘今天是{0:%Y}年{0:%m}月{0:%d}日‘.format(time)) print(‘今天是这周的第%s天‘%time.strftime(‘%w‘)) print(‘今天是今年的第%s天‘%time.strftime(‘%j‘)) print(‘今天是今年的第%s周‘%time.strftime(‘%W‘)) print(‘今天是当月的第%s天‘%time.strftime(‘%d‘))
标签:ber date ftime mat time style 指定 form 输出
原文地址:http://www.cnblogs.com/Qzlhxxx/p/7615780.html