Create a unique number with javascript time

后端 未结 30 3157
生来不讨喜
生来不讨喜 2020-12-02 08:31

I need to generate unique id numbers on the fly using javascript. In the past, I\'ve done this by creating a number using time. The number would be made up of the four digi

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 08:49

    Using toString(36), slightly slow, here is the faster and unique solution:

    new Date().getUTCMilliseconds().toString() +
    "-" +
    Date.now() +
    "-" +
    filename.replace(/\s+/g, "-").toLowerCase()
    

提交回复
热议问题