发布时间:2019-09-25 08:21:37编辑:auto阅读(2229)
有时候业务需要,需要把正常的时间格式与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编解码实
49360
48552
39252
36336
30750
27559
26558
21376
21233
19580
220°
457°
444°
541°
888°
610°
1286°
1403°
1215°
1204°