一、10位时间戳
__author__ = 'liwanpeng'
import time
def get_10_current_timestamp():
'''
函数功能:当前时间时间戳的获取
'''
t = time.time()
pirnt int(t)
def get_10_timestamp():
'''
函数功能:获取特定时间的时间戳;时间字符串->时间戳
'''
dt = '2017-12-20 12:00:00'
timearray = time.strptime(dt, '%Y-%m-%d %H:%M:%S')
timestamp = int(time.mktime(timearray))
print timestamp
print type(timestamp)
return timestamp
def timestamp10_to_timestr(timestamp):
'''
函数功能:将10位的时间戳转换成时间字符串;时间戳->字符串
'''
timestr = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))
print timestr
return timestr
二、13位时间戳
__author__ = 'liwanpeng'
def get_13_timestamp():
'''
函数功能:获取当前时间的时间戳(13位)
'''
timestamp = time.time()
return int(round(timestamp) * 1000)
def timestr_to_13timestamp():
'''
函数作用:将制定的时间字符串转换成13位时间戳
'''
time = '2017-12-20 12:00:00'
timearray = time.strptime(dt, '%Y-%m-%d %H:%M:%S')
timestamp13 = int(time,mktime(timearray))
return int(round(timestamp * 1000))