标签:day ber com date from 字符串转换 创建 http 今天
from datetime import datetime now=datetime.now() utcnow=datetime.utcnow() #获取当前datetime print(‘当前时间为:‘,now) print(‘当前国际时间为:‘,utcnow) #用指定日期时间创建datetime dt=datetime(2017,5,23,12,20) print(dt) #将字符串转换成datetime类型 d1=datetime.strptime(‘2017/9/30‘,‘%Y/%m/%d‘) d2=datetime.strptime(‘2017年9月30日星期六‘,‘%Y年%m月%d日星期六‘) d3=datetime.strptime(‘2017年9月30日星期六8时42分24秒‘,‘%Y年%m月%d日星期六%H时%M分%S秒‘) d4=datetime.strptime(‘9/30/2017‘,‘%m/%d/%Y‘) d5=datetime.strptime(‘9/30/2017 8:42:50‘,‘%m/%d/%Y %H:%M:%S‘) print(d1,‘\n‘,d2,‘\n‘,d3,‘\n‘,d4,‘\n‘,d5) #将datetime类型转换成字符串 print(now.strftime(‘%Y年%m月%d日%A%H时%M分%S秒‘)) print(now.strftime(‘%A,%B %d,%Y‘)) print(now.strftime(‘%m/%d/%Y %I:%M:%S%p‘)) print(now.strftime(‘%B %d,%Y‘)) #用datetime类型的变量输出以下字符串 print(now.strftime(‘今天是%Y年%m月%d日‘)) print(now.strftime(‘今天是这周的第%w天‘)) print(now.strftime(‘今天是今年的第%j天‘)) print(now.strftime(‘今周是今年的第%W周‘)) print(now.strftime(‘今天是当月的第%d天‘))
标签:day ber com date from 字符串转换 创建 http 今天
原文地址:http://www.cnblogs.com/wujialing/p/7614288.html