Create a unique number with javascript time

后端 未结 30 2977
生来不讨喜
生来不讨喜 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:37

    This can be achieved simply with the following code:

    var date = new Date();
    var components = [
        date.getYear(),
        date.getMonth(),
        date.getDate(),
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
        date.getMilliseconds()
    ];
    
    var id = components.join("");
    

提交回复
热议问题