How do you get a timestamp in JavaScript?

前端 未结 30 3580
情深已故
情深已故 2020-11-21 15:19

How can I get a timestamp in JavaScript?

Something similar to Unix timestamp, that is, a single number that represents the current time and date. Either as a number

30条回答
  •  深忆病人
    2020-11-21 15:47

    Here is a simple function to generate timestamp in the format: mm/dd/yy hh:mi:ss

    function getTimeStamp() {
        var now = new Date();
        return ((now.getMonth() + 1) + '/' +
                (now.getDate()) + '/' +
                 now.getFullYear() + " " +
                 now.getHours() + ':' +
                 ((now.getMinutes() < 10)
                     ? ("0" + now.getMinutes())
                     : (now.getMinutes())) + ':' +
                 ((now.getSeconds() < 10)
                     ? ("0" + now.getSeconds())
                     : (now.getSeconds())));
    }
    

提交回复
热议问题