js中?new?Date().getTime()得到的是毫秒數(shù)時間戳
應(yīng)用實例
var filename = '/demoad.css?' + new Date().getTime();
js中 var time = new Date().getTime()得到的是毫秒數(shù)
1、時間戳轉(zhuǎn)日期字符串
function getLocalTime(nS) { var d = new Date(parseInt(nS)* 1000); //根據(jù)時間戳生成的時間對象 var date = (d.getFullYear()) + "-" + (d.getMonth() + 1) + "-" + (d.getDate()) + " " + (d.getHours()) + ":" + (d.getMinutes()) + ":" + (d.getSeconds()); return date; } document.write(getLocalTime(1552889937));
2、當(dāng)前時間換時間戳
var timestamp = parseInt(new Date().getTime()/1000); // 當(dāng)前時間戳 document.write(timestamp);
3、當(dāng)前時間換日期字符串
var now = new Date(); var yy = now.getFullYear(); //年 var mm = now.getMonth() + 1; //月 var dd = now.getDate(); //日 var hh = now.getHours(); //時 var ii = now.getMinutes(); //分 var ss = now.getSeconds(); //秒 var clock = yy + "-"; if(mm < 10) clock += "0"; clock += mm + "-"; if(dd < 10) clock += "0"; clock += dd + " "; if(hh < 10) clock += "0"; clock += hh + ":"; if (ii < 10) clock += '0'; clock += ii + ":"; if (ss < 10) clock += '0'; clock += ss; document.write(clock); //獲取當(dāng)前日期
4、日期字符串轉(zhuǎn)時間戳
var date = '2015-03-05 17:59:00.0'; date = date.substring(0,19); date = date.replace(/-/g,'/'); var timestamp = new Date(date).getTime(); document.write(timestamp);
5、時間戳轉(zhuǎn)日期字符串
var timestamp = '1425553097'; var d = new Date(timestamp * 1000); //根據(jù)時間戳生成的時間對象 var date = (d.getFullYear()) + "-" + (d.getMonth() + 1) + "-" + (d.getDate()) + " " + (d.getHours()) + ":" + (d.getMinutes()) + ":" + (d.getSeconds()); document.write(date);
更多的關(guān)于時間戳的可以參考這篇文章 http://www.dbjr.com.cn/article/278265.htm
到此這篇關(guān)于js中 new Date().getTime()得到的是毫秒數(shù)時間戳的文章就介紹到這了,更多相關(guān)js時間戳內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
js實現(xiàn)的點擊div區(qū)域外隱藏div區(qū)域
這篇文章主要介紹了通過js實現(xiàn)點擊div區(qū)域外隱藏div區(qū)域,原理及示例代碼如下2014-06-06如何通過Proxy實現(xiàn)JSBridge模塊化封裝
這篇文章主要介紹了如何通過Proxy實現(xiàn)JSBridge模塊化封裝,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-10-10使用javascript實現(xiàn)json數(shù)據(jù)以csv格式下載
這篇文章主要介紹了使用javascript實現(xiàn)json數(shù)據(jù)以csv格式下載,需要的朋友可以參考下2015-01-01詳解layui?laydate選擇時間的回調(diào)方法
這篇文章主要介紹了layui?laydate選擇時間的回調(diào)方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01javascript 關(guān)鍵字高亮顯示實現(xiàn)代碼
屏蔽HTML標(biāo)簽,支持多關(guān)鍵字(以空格間隔),關(guān)鍵字內(nèi)可含有特殊字符2010-09-09