The content of this article is about how to format the timestamp function in JavaScript (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
formatDate(v) { if (/^(-)?\d{1,10}$/.test(v)) { v = v * 1000; } else if (/^(-)?\d{1,13}$/.test(v)) { v = v * 1; } var dateObj = new Date(v); var month = dateObj.getMonth() + 1; var day = dateObj.getDate(); var hours = dateObj.getHours(); var minutes = dateObj.getMinutes(); var seconds = dateObj.getSeconds(); if(month<10){ month = "0" + month; } if(day<10){ day = "0" + day; } if(hours<10){ hours = "0" + hours; } if(minutes<10){ minutes = "0" + minutes; } if(seconds<10){ seconds = "0" + seconds; } var UnixTimeToDate = dateObj.getFullYear() + '-' + month + '-' +day + ' ' + hours + ':' + minutes + ':' + seconds; return UnixTimeToDate; }
Related recommendations:
js formatted time and js formatted timestamp example_Basic knowledge
The above is the detailed content of How to format timestamp function in javascript (with code). For more information, please follow other related articles on the PHP Chinese website!