python转化13位时间戳


 1 # -*- coding: utf-8 -*-
 2 
 3 def get_time_stamp13(datetime_obj):
 4     import datetime, time
 5     # 生成13时间戳   eg:1557842280000
 6     datetime_str = datetime.datetime.strftime(datetime_obj, '%Y-%m-%d %H:%M:00')
 7     datetime_obj = datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:00')
 8     print(datetime_obj)
 9     # 10位,时间点相当于从1.1开始的当年时间编号
10     date_stamp = str(int(time.mktime(datetime_obj.timetuple())))
11     # 3位,微秒
12     data_microsecond = str("%06d" % datetime_obj.microsecond)[0:3]
13     date_stamp = date_stamp + data_microsecond
14     return int(date_stamp)

使用

# -*- coding: utf-8 -*-
from get_time_stamp13 import get_time_stamp13
import datetime, time
now_time = datetime.datetime.now()
start_time = now_time - datetime.timedelta(minutes=2)
end_time = now_time + datetime.timedelta(minutes=1)
start_time_stamp = get_time_stamp13(start_time)
end_time_stamp = get_time_stamp13(end_time)

print(start_time_stamp)
print(end_time_stamp)

  详见:https://blog.csdn.net/qq_31603575/article/details/83343791


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM