php-app开发接口加密的示例分析
218
2022-09-04
python 时间
1.字符串格式的时间转时间戳
import timea = "2022-04-19 08:51:31"#先转换成时间数组time_array = time.strptime(a,'%Y-%m-%d %H:%M:%S')print(time_array)#时间数组转时间戳time_stamp =int(time.mktime(time.strptime(a,'%Y-%m-%d %H:%M:%S')))print(time_stamp)
结果:
time.struct_time(tm_year=2022, tm_mon=4, tm_mday=19, tm_hour=8, tm_min=51, tm_sec=31, tm_wday=1, tm_yday=109, tm_isdst=-1)
1650329491
2.字符串时间戳转时间
import timetime_stamp = 1650329491#转时间数组time_array = time.localtime(time_stamp)print(time_array)#转时间time_time = time.strftime("%Y-%m-%d %H:%M:%S", time_array)print(time_time)
结果:
time.struct_time(tm_year=2022, tm_mon=4, tm_mday=19, tm_hour=8, tm_min=51, tm_sec=31, tm_wday=1, tm_yday=109, tm_isdst=0)
2022-04-19 08:51:31
3.常用的时间练习
import timeclass Time(): def now_time(self): return time.strftime('%H:%M:%S', time.localtime(time.time())) def now_date(self): return time.strftime('%Y-%m-%d', time.localtime(time.time())) def now_date_time(self): return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) def now_time_stamp_10(self): return int(time.time()) def now_time_stamp_13(self): return int(time.time()*1000)if __name__ == '__main__': ss=Time() print(ss.now_time()) print(ss.now_date()) print(ss.now_date_time()) print(ss.now_time_stamp_10()) print(ss.now_time_stamp_13())
搜索
复制
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~