# -*- coding:utf-8 -*-
import time
import datetime
def millisecond_to_time(millis):
"""13位时间戳转换为日期格式字符串"""
return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(millis/1000))
# -*- coding: utf-8 -*-
def get_time_stamp13(datetime_obj):
import datetime, time
# 生成13时间戳 eg:1557842280000
datetime_str = datetime.datetime.strftime(datetime_obj, '%Y-%m-%d %H:%M:%S')
datetime_obj = datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')
print(datetime_obj)
# 10位,时间点相当于从1.1开始的当年时间编号
date_stamp = str(int(time.mktime(datetime_obj.timetuple())))
# 3位,微秒
data_microsecond = str("%06d" % datetime_obj.microsecond)[0:3]
date_stamp = date_stamp + data_microsecond
return int(date_stamp)
start_time=datetime.datetime(2018,04,8 ,13,55,39)
start_time_stamp = get_time_stamp13(start_time)
print start_time_stamp
print millisecond_to_time(1523166927472)
import datetime
aa= ((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M"))
bb= ((datetime.datetime.now() - datetime.timedelta(minutes=1)).strftime("%Y-%m-%d %H:%M"))
#cc= ((datetime.datetime.now() - datetime.timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M"))
cc=datetime.datetime.strptime(bb, '%Y-%m-%d %H:%M')
dd=datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
ee=datetime.datetime.strptime(dd, '%Y-%m-%d %H:%M')
print aa
print bb
print cc
print dd
print ee
print type(ee)
#print get_time_stamp13(bb)
print get_time_stamp13(cc)
print get_time_stamp13(ee)
print millisecond_to_time(1645168680000)
print millisecond_to_time(1645168740000)
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled2/http/t18.py
2018-04-08 13:55:39
1523166939000
2018-04-08 13:55:27
2022-02-17 15:19
2022-02-18 15:18
2022-02-18 15:18:00
2022-02-18 15:19
2022-02-18 15:19:00
2022-02-18 15:18:00
1645168680000
2022-02-18 15:19:00
1645168740000
2022-02-18 15:18:00
2022-02-18 15:19:00
Process finished with exit code 0