本文实例讲述了JS自定义函数实现时间戳转换成date的方法。分享给大家供大家参考,具体如下:
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>获取当前年/月/日(www.vevb.com)</title></head><body><script>function UnixToDate(unixTime, timeZone) { if (typeof (timeZone) == 'number') { unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60; } var now = new Date(unixTime * 1000); var year=now.getFullYear(); var month=now.getMonth()+1; var date=now.getDate(); var hour=now.getHours(); var minute=now.getMinutes(); return year+"/"+month+"/"+date+" "+hour+":"+minute ;}var m_time = parseInt(new Date().getTime()/1000); var m_date = UnixToDate(m_time) ;document.write(m_date);</script></body></html>
运行结果:
2017/8/27 12:4
希望本文所述对大家JavaScript程序设计有所帮助。
新闻热点
疑难解答