當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
javascript:时间戳转换为日期时间
生活随笔
收集整理的這篇文章主要介紹了
javascript:时间戳转换为日期时间
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
首先,在script里面,定義一個方法,具體如下:
function formatDate(now) {var year = now.getFullYear(),month = now.getMonth() + 1,date = now.getDate(),hour = now.getHours(),minute = now.getMinutes(),second = now.getSeconds();return year + "-" + month + "-" + date;}然后再處理接收過來的時間戳數(shù)據(jù)
var time = formatDate(new Date(data['time']*1000));【注意事項】
1、在調用formatDate方法時,切記里面要有new Date。
2、另外,得到的時間,必須乘以1000。(具體為啥我也不知道,網上有不少說出現(xiàn)NaN-NaN-NaN的解決方法,感覺都不如這個好使。
總結
以上是生活随笔為你收集整理的javascript:时间戳转换为日期时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库之架构
- 下一篇: gradle idea java ssm