发布时间:2019-09-25 08:21:37编辑:auto阅读(2853)
有时候业务需要,需要把正常的时间格式与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编解码实
53046
39975
34353
30109
25002
24808
23181
16647
14822
14321
637°
599°
659°
667°
720°
845°
815°
842°
931°
854°