标签:button 获取 comment apt 偏移量 rsa 结构 当前时间 %s
print(time.time())
>>>1539847769.6119404
print(time.localtime())
>>>time.struct_time(tm_year=2018, tm_mon=10, tm_mday=18, tm_hour=15, tm_min=35, tm_sec=0, tm_wday=3, tm_yday=291, tm_isdst=0)
print(time.mktime(time.localtime()))
>>>1539849828.0
print(time.time())
1539849828.090503
print(time.strftime("%Y-%m-%d %H:%M:%S"))
>>>2018-10-18 15:56:42
print(time.strptime("2018-10-18 15:56:42","%Y-%m-%d %H:%M:%S"))
>>>time.struct_time(tm_year=2018, tm_mon=10, tm_mday=18, tm_hour=15, tm_min=56, tm_sec=42, tm_wday=3, tm_yday=291, tm_isdst=-1)
print(time.gmtime(time.time()))
>>>time.struct_time(tm_year=2018, tm_mon=10, tm_mday=18, tm_hour=8, tm_min=10, tm_sec=16, tm_wday=3, tm_yday=291, tm_isdst=0)
附一:
附二:time 时间之间的转换
datetime 模块定义了 5 个类,分别是
print(datetime.date(2017,12,1))
>>>2017-12-01
print(datetime.date.today())
>>>2018-10-18
a = datetime.date.today()
print(datetime.date.isoweekday(a))
>>>4
a = datetime.date.today()
print(datetime.date.weekday(a))
>>>3
print(datetime.date.fromtimestamp(1539847769))
>>>2018-10-18
a = datetime.date.today()
print(a.timetuple())
>>>time.struct_time(tm_year=2018, tm_mon=10, tm_mday=18, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=291, tm_isdst=-1)
a = datetime.date.today()
print(a.replace(year=2010))
>>>2010-10-18
time 类有 5 个参数,datetime.time (hour,minute,second,microsecond,tzoninfo)
print(datetime.time(8,5,32))
print(datetime.time(8,5,32,32))
>>>08:05:32
>>>08:05:32.000032
cls.strftime ("时间格式")
指定时间格式
a= datetime.time(8,5,32,32)
print(a.strftime("%H:%M"))
>>>08:05
cls.replace()
替换时分秒
a= datetime.time(8,5,32,32)
print(a.replace(hour=18))
>>>18:05:32.000032
datetime.time.tzname()
返回时区名字:略
datetime.time.utcoffset()
返回时区的时间偏移量:略
datetime 模块类的使用大同小异,有很多方法我们可能这辈子都用不上,datetime 类的方法比较多,在这里我就捡重点的列一下:
print(datetime.datetime.now())
>>>2018-10-18 19:15:17.691425
print(datetime.datetime.now().date())
>>>2018-10-18
print(datetime.datetime.now().time())
>>>19:16:54.497104
print(datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S‘))
>>>2018-10-18 19:21:13
a = datetime.datetime.strptime("2018-10-18 19:21:37",‘%Y-%m-%d %H:%M:%S‘)
print(a,type(a))
>>>2018-10-18 19:21:37 <class ‘datetime.datetime‘>
datetime.datetime.timedelta 用于计算两个日期之间的差值:
import datetime
a = datetime.datetime(2015, 10, 3)
b = datetime.datetime.now()
res1 = (b - a)
res2 = (b - a).days // 取时间差天数
res3 = (b - a).seconds // 取时间差时分秒部分的秒数总和
res4 = (b - a).microseconds // 取时间差 秒数之后的微秒数
res5 = (b - a).total_seconds() // 时间差的总秒数
print(res1) >>> 1111 days, 19:48:35.543523
print(res2) >>> 1111
print(res3) >>> 71315
print(res4) >>> 71315
print(res5) >>> 96061715.543523
标签:button 获取 comment apt 偏移量 rsa 结构 当前时间 %s
原文地址:https://www.cnblogs.com/reaix/p/12268029.html