源码:
#!/usr/bin/python3
import time
# 格式化成2016-03-20 11:45:39形式
print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
# 格式化成Sat Mar 28 22:24:24 2016形式
print (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
# 将格式字符串转换为时间戳
a = "Sat Mar 28 22:24:24 2016"
print (time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))
通过时间戳获取hash
import datetime
import hashlib
print(str(datetime.datetime.now()))
hash_value = hashlib.sha256(str(datetime.datetime.now()).encode("utf8"))
print(hash_value.hexdigest())
结果:
2016-04-07 10:29:46
Thu Apr 07 10:29:46 2016
1459175064.0
2020-10-29 11:24:56.911750
155dfb90d83ccfa74217c1dac48f1d03e6ea1a323f16cf3d0b8c0450d091092d