當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS DATE对象详解
生活随笔
收集整理的這篇文章主要介紹了
JS DATE对象详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、建立時間對象:可獲取年,月,日,星期,時,分,秒
var d = new Date(); console.log(d.getFullYear()+'年'+d.getMonth()+'月'+d.getDate()+'星期'+d.getDay()+'日'+d.getHours()+'小時'+d.getMinutes()+'分'+d.getSeconds()+'秒');?2、獲取時間戳
console.log(d.getTime());?3、時間轉換公式
Math.floor(t/86400) //天Math.floor(t%86400/3600) //時Math.floor(t%86400%3600/60) //分t%60 //秒?4、js格式化日期
var format = function(time, format){var t = new Date(time);var tf = function(i){return (i < 10 ? '0' : '') + i};return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){switch(a){case 'yyyy':return tf(t.getFullYear());break;case 'MM':return tf(t.getMonth() + 1);break;case 'mm':return tf(t.getMinutes());break;case 'dd':return tf(t.getDate());break;case 'HH':return tf(t.getHours());break;case 'ss':return tf(t.getSeconds());break;}}) } format(new Date().getTime(), 'yyyy-MM-dd HH:mm:ss')//getTime返回距 1970 年 1 月 1 日之間的毫秒數?
轉載于:https://www.cnblogs.com/ilovexiaoming/p/4630583.html
總結
以上是生活随笔為你收集整理的JS DATE对象详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle - 行转列, 列转行
- 下一篇: Redis简介 与Memcache的区