有没有做文创的网站,旅游网站建设的市场分析,免费做二维码网站,苏州园区做网站开发中经常会对时间格式处理#xff0c;对于时间数据#xff0c;比如2019-02-28 10:23:29#xff0c;有时需要日期与时间戳进行相互转换#xff0c;在Python3中主要用到time模块#xff0c;相关的函数如下#xff1a;其中unix_time函数是正常时间转unix时间戳#xff0c…开发中经常会对时间格式处理对于时间数据比如2019-02-28 10:23:29有时需要日期与时间戳进行相互转换在Python3中主要用到time模块相关的函数如下其中unix_time函数是正常时间转unix时间戳date_time是unix时间转正常时间如年月日时分秒import time日期转时间戳def unix_time(dt):# 转换成时间数组timeArray time.strptime(dt, %Y-%m-%d %H:%M:%S)# 转换成时间戳timestamp int(time.mktime(timeArray))return timestamp时间戳转日期def custom_time(timestamp):# 转换成localtimetime_local time.localtime(timestamp)# 转换成新的时间格式(2016-05-05 20:28:54)dt time.strftime(%Y-%m-%d %H:%M:%S, time_local)return dttime_now 2019-02-28 10:23:29unix_t unix_time(time_now)custom_t custom_time(unix_t)print(unix_t) # 1551320609print(custom_t) # 2019-02-28 10:23:29# 如果是自定义的时间格式转换呢思路方法雷同比如下时间用指定格式显示,比如 年-月-日 转 年/月/日dt 2020-10-10 22:20:20# 转为数组timeArray time.strptime(dt, %Y-%m-%d %H:%M:%S)# 转为其它显示格式customTime time.strftime(%Y/%m/%d %H:%M:%S, timeArray)print(customTime) # 2020/10/10 22:20:20时间用指定格式显示,比如 年/月/日 转 年-月-日dt 2020/10/10 22:20:20timeArray time.strptime(dt, %Y/%m/%d %H:%M:%S)customTime time.strftime(%Y-%m-%d %H:%M:%S, timeArray)print(customTime) # 2020-10-10 22:20:20无论从事什么行业只要做好两件事就够了一个是你的专业、一个是你的人品专业决定了你的存在人品决定了你的人脉剩下的就是坚持用善良專業和真诚赢取更多的信任。