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

后端 未结 5 598
旧巷少年郎
旧巷少年郎 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条回答
  •  伪装坚强ぢ
    2021-02-02 17:55

    What about changing the base of current milliseconds since epoch. For example, in JavaScript, changing to base 36:

    Date.now().toString(36)
    

    Results in :

    "jv8pvlbg"
    

    That should be a safe hash, up to milliseconds, respect date order and smaller than 10.

    The only thing is that is not safe, but in your case security is not important right?

    Sorry I don't have the answer for python, but it should by straightforward and should nor require any library. My two cents.

提交回复
热议问题