Python之日期与时间处理模块(date和datetime)
https://www.cnblogs.com/yyds/p/6369211.html
https://blog.csdn.net/u013317445/article/details/86412417
https://blog.csdn.net/lc11535/article/details/103114310
https://blog.csdn.net/qq_18299691/article/details/82941947
https://blog.csdn.net/x18835129278/article/details/89955801
https://www.cnblogs.com/mashuqi/p/11576705.html
2、自己写得代码:
import time
import datetime
获得两端日期的天数
start_time = ‘2021-03-08’
end_time = ‘2021-06-15’
start = time.mktime(time.strptime(start_time, ‘%Y-%m-%d’))
end = time.mktime(time.strptime(end_time, ‘%Y-%m-%d’))
count_days = int((end - start) / (24 * 60 * 60))
print(count_days)
获得当前时间及输出时间字符串:
print(time.strftime("%Y-%m-%d", time.localtime()))
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print(time.strftime("%Y%m%d%H%M%S", time.localtime()))
#求时间,间隔方法1
starttime = datetime.datetime.now()
long running
time.sleep(2)
endtime = datetime.datetime.now()
duringtime = endtime - starttime
print(duringtime.seconds)
#datetime的输出看看有什么内容。
print(datetime.datetime.now())
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
print(datetime.datetime.now().strftime("%Y%m%d%H%M%S%f"))
#求时间,间隔方法2
a = time.time()
short running
time.sleep(3)
b = time.time()
seconds = b - a
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print("%02d:%02d:%02d" % (h, m, s))
#自己输出的
print(f"{h}:{m}:{s}".replace(".", “”))
时间戳的获取
t = time.time()
print (t) #原始时间数据
print (int(t)) #秒级时间戳
print (int(round(t * 1000))) #毫秒级时间戳
print (int(round(t * 1000000))) #微秒级时间戳
print(int(round(time.time() * 10000000000))) #时间戳(乘10个零)