c++获取时间戳_Python你想知道的时间格式Time都在这里

公众号:pythonislover

import time#1553580512.129654 时间戳格式#时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
print(time.time())#time.struct_time(tm_year=2019, tm_mon=3, tm_mday=26, tm_hour=14, tm_min=9, tm_sec=3, tm_wday=1, tm_yday=85, tm_isdst=0) 元祖格式
print(time.localtime())#可以把时间戳格式的值传入元祖格式最中,进行转换#time.struct_time(tm_year=2016, tm_mon=1, tm_mday=24, tm_hour=4, tm_min=21, tm_sec=52, tm_wday=6, tm_yday=24, tm_isdst=0)
print(time.localtime(1453580512.129654))#2019 对元祖时间格式,我们可以做操作,取里面的特定年月日
time_tuple = time.localtime()
print(time_tuple.tm_year)# 2019-03-26 14:11:04 字符串格式
print( time.strftime("%Y-%m-%d %X"))#时间格式的转换#1.时间戳格式 -----> 元祖格式转换#localtime/gmtime
print(time.localtime(3600*24))
print(time.gmtime(3600*24))#2.元祖格式 -----> 时间戳格式转换#mktime
print(time.mktime(time.localtime()))#3.元祖格式 -----> 字符串格式转换
print(time.strftime("%Y-%m-%d %X", time.localtime()))#4.字符串格式 -----> y元祖格式转换
print(time.strptime("2019-03-26","%Y-%m-%d"))#5.time sleep 功能#睡3秒
time.sleep(3)时间格式转换图:

7d8ce1194f2e06c9c11eef670135e34a.png

format time结构化表示格式含义%a本地(locale)简化星期名称%A本地完整星期名称%b本地简化月份名称%B本地完整月份名称%c本地相应的日期和时间表示%d一个月中的第几天(01 - 31)%H一天中的第几个小时(24小时制,00 - 23)%I第几个小时(12小时制,01 - 12)%j一年中的第几天(001 - 366)%m月份(01 - 12)%M分钟数(00 - 59)%p本地am或者pm的相应符%S秒(01 - 61)%U一年中的星期数。(00 - 53星期天是一个星期的开始。)第一个星期天之前的所有天数都放在第0周。%w一个星期中的第几天(0 - 6,0是星期天)%W和%U基本相同,不同的是%W以星期一为一个星期的开始。%x本地相应日期%X本地相应时间%y去掉世纪的年份(00 - 99)%Y完整的年份%Z时区的名字(如果不存在为空字符)%%‘%’字符DATE类:from datetime import *import time# date.max: 9999-12-31# date.min: 0001-01-01# date.today(): 2019-03-26# date.fromtimestamp(): 2019-03-26
print('date.max:', date.max)
print('date.min:', date.min)
print('date.today():', date.today())
print('date.fromtimestamp():', date.fromtimestamp(time.time()))# now: 2019-03-26 , tomorrow: 2019-03-27# timetuple(): time.struct_time(tm_year=2019, tm_mon=3, tm_mday=26, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=85, tm_isdst=-1)# weekday(): 1# isoweekday(): 2# isocalendar(): (2019, 13, 2)# isoformat(): 2019-03-26# ('strftime():', '2019-03-26')
now = date(2019, 3, 26)
tomorrow = now.replace(day = 27)
print('now:', now, ', tomorrow:', tomorrow)
print('timetuple():', now.timetuple())
print('weekday():', now.weekday())
print('isoweekday():', now.isoweekday())
print('isocalendar():', now.isocalendar())
print('isoformat():', now.isoformat())
print(('strftime():', now.strftime("%Y-%m-%d")))DATETIME类:from datetime import *import time
print('############################################')# datetime.max: 9999-12-31 23:59:59.999999# datetime.min: 0001-01-01 00:00:00# datetime.resolution: 0:00:00.000001# today(): 2019-03-26 14:31:24.194149# now(): 2019-03-26 14:31:24.194149# utcnow(): 2019-03-26 06:31:24.194149# fromtimestamp(tmstmp): 2019-03-26 14:31:24.194149# ('utcfromtimestamp(tmstmp):', datetime.datetime(2019, 3, 26, 6, 31, 24, 194149))
print('datetime.max:', datetime.max)
print('datetime.min:', datetime.min)
print('datetime.resolution:', datetime.resolution)
print('today():', datetime.today())
print('now():', datetime.now())
print('utcnow():', datetime.utcnow())
print('fromtimestamp(tmstmp):', datetime.fromtimestamp(time.time()))
print(('utcfromtimestamp(tmstmp):', datetime.utcfromtimestamp(time.time())))# 方法和属性# dt=datetime.now()#datetime对象# dt.year、month、day、hour、minute、second、microsecond、tzinfo:# dt.date():获取date对象;# dt.time():获取time对象;# dt. replace ([ year[ , month[ , day[ , hour[ , minute[ , second[ , microsecond[ , tzinfo] ] ] ] ] ] ] ]):# dt. timetuple ()# dt. utctimetuple ()# dt. toordinal ()# dt. weekday ()# dt. isocalendar ()# dt. isoformat ([ sep] )# dt. ctime ():返回一个日期时间的C格式字符串,等效于time.ctime(time.mktime(dt.timetuple()));# dt. strftime (format)# import time

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值