How to generate a fixed-length hash based on current date and time in Python?

后端 未结 5 603
旧巷少年郎
旧巷少年郎 2021-02-02 17:46

I want to generate a fixed-length (say 10 characters) hash based on current date & time. This hash will be append to names of the uploaded files from my users. How can I do

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-02 17:52

    Batteries included:

    import hashlib
    import time
    
    hash = hashlib.sha1()
    hash.update(str(time.time()))
    print hash.hexdigest()
    print hash.hexdigest()[:10]
    

提交回复
热议问题