English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript needs to convert timestamps to a common format, which may not be needed in most cases.
Let's take a look at the first one first.
function getLocalTime(nS) { return new Date(parseInt(nS * 1000/:\d{1,2$/,' '); }); alert(getLocalTime(1293072805))
The second type
function getLocalTime(nS) { return new Date(parseInt(nS * 10).toLocaleString().substr(0,17)} alert(getLocalTime(1293072805))
Regular expression replacement
function getLocalTime(nS) { return new Date(parseInt(nS * 1000/Year|Month/g, "-).replace(/Day/g, " "); }); alert(getLocalTime(1177824835))
The third type
function formatDate(now) { var year=now.getYear(); var month=now.getMonth()+1; var date=now.getDate(); var hour=now.getHours(); var minute=now.getMinutes(); var second=now.getSeconds(); return year+"-"+month+"-"+date+" "+hour+:+minute+:+second; }); var d=new Date(1230999938); alert(formatDate(d));
That's all for this article. I hope it will be helpful to everyone's learning and that everyone will support the Yelling Tutorial more.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)