Python 获取当前时间或当前时间戳,通过时间戳获取hash
生活随笔
收集整理的這篇文章主要介紹了
Python 获取当前时间或当前时间戳,通过时间戳获取hash
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
源碼:?
#!/usr/bin/python3import 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()))# 將格式字符串轉(zhuǎn)換為時(shí)間戳 a = "Sat Mar 28 22:24:24 2016" print (time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))通過時(shí)間戳獲取hash import datetime import hashlibprint(str(datetime.datetime.now()))hash_value = hashlib.sha256(str(datetime.datetime.now()).encode("utf8")) print(hash_value.hexdigest())結(jié)果:
2016-04-07 10:29:46 Thu Apr 07 10:29:46 2016 1459175064.02020-10-29 11:24:56.911750 155dfb90d83ccfa74217c1dac48f1d03e6ea1a323f16cf3d0b8c0450d091092d?
總結(jié)
以上是生活随笔為你收集整理的Python 获取当前时间或当前时间戳,通过时间戳获取hash的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python name ‘basestr
- 下一篇: Python__repr__()方法:显