Home > Web Front-end > JS Tutorial > body text

js timestamp conversion date

PHP中文网
Release: 2017-07-12 18:10:31
Original
1214 people have browsed it
<span style="color: #0000ff">//js时间戳转换日期<br>function</span><span style="color: #000000"> formatDate(now) {
    </span><span style="color: #0000ff">var</span> year=<span style="color: #000000">now.getFullYear();
    </span><span style="color: #0000ff">var</span> month=now.getMonth()+1<span style="color: #000000">;
    </span><span style="color: #0000ff">var</span> date=<span style="color: #000000">now.getDate();
    </span><span style="color: #0000ff">var</span> hour=<span style="color: #000000">now.getHours();
    </span><span style="color: #0000ff">var</span> minute=<span style="color: #000000">now.getMinutes();
    </span><span style="color: #0000ff">var</span> second=<span style="color: #000000">now.getSeconds();
    </span><span style="color: #0000ff">return</span> year+"-"+month+"-"+date+" "+hour+":"+minute+":"+<span style="color: #000000">second;
}

</span><span style="color: #0000ff">var</span> d=<span style="color: #0000ff">new</span><span style="color: #000000"> Date(时间戳(毫秒));
alert(formatDate(d));</span>
Copy after login

 

The above is the detailed content of js timestamp conversion date. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template