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