发布时间:2019-09-25 08:21:37编辑:auto阅读(3194)
有时候业务需要,需要把正常的时间格式与unix时间戳格式进行转换。
在python中转化方式如下,直接利用time中的函数:
#! /usr/bin/env python
#coding:utf-8
import sys,os,re
import time
def timestamp_datatime(value):
format = '%Y-%m-%d %H:%M'
#format = '%Y-%m-%d %H:%M:%S'
#value 为时间戳值,如:1460073600.0
value = time.localtime(value)
dt = time.strftime(format,value)
return dt
def datetime_timestamp(dt):
time.strptime(dt,'%Y-%m-%d %H:%M')
s = time.mktime(time.strptime(dt,'%Y-%m-%d %H:%M'))
return s
if __name__ == '__main__':
d = datetime_timestamp('2016-04-08 08:00')
print d
s = timestamp_datatime(1460073600.0)
print s
上一篇: centos7上配置python3环境和
下一篇: 使用python3的base64编解码实
54995
41791
36381
31791
26698
26385
24908
20515
16457
15876
3022°
2748°
2832°
2988°
2925°
3188°
3076°
2925°
2912°
2896°