亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js中?new?Date().getTime()得到的是毫秒數(shù)時(shí)間戳

 更新時(shí)間:2023年07月02日 10:56:39   作者:萬(wàn)筱武  
今天在寫一個(gè)函數(shù)的時(shí)候需要用的一個(gè)時(shí)間戳方便調(diào)用不同的隨機(jī)數(shù)?那么時(shí)間戳就是比較好的方式,主要怕瀏覽器緩存數(shù)據(jù),下面就為大家簡(jiǎn)單介紹一下

應(yīng)用實(shí)例

var filename = '/demoad.css?' + new Date().getTime();

js中 var time = new Date().getTime()得到的是毫秒數(shù)

1、時(shí)間戳轉(zhuǎn)日期字符串

function getLocalTime(nS) {     
		var d = new Date(parseInt(nS)* 1000);    //根據(jù)時(shí)間戳生成的時(shí)間對(duì)象
		var date = (d.getFullYear()) + "-" + 
					(d.getMonth() + 1) + "-" +
					(d.getDate()) + " " + 
					(d.getHours()) + ":" + 
					(d.getMinutes()) + ":" + 
					(d.getSeconds()); 
		return date;   
}
document.write(getLocalTime(1552889937));

2、當(dāng)前時(shí)間換時(shí)間戳

var timestamp = parseInt(new Date().getTime()/1000);    // 當(dāng)前時(shí)間戳
document.write(timestamp);

3、當(dāng)前時(shí)間換日期字符串

var now = new Date();
var yy = now.getFullYear();      //年
var mm = now.getMonth() + 1;     //月
var dd = now.getDate();          //日
var hh = now.getHours();         //時(shí)
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)時(shí)間戳

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、時(shí)間戳轉(zhuǎn)日期字符串

var timestamp = '1425553097';
var d = new Date(timestamp * 1000);    //根據(jù)時(shí)間戳生成的時(shí)間對(duì)象
var date = (d.getFullYear()) + "-" + 
           (d.getMonth() + 1) + "-" +
           (d.getDate()) + " " + 
           (d.getHours()) + ":" + 
           (d.getMinutes()) + ":" + 
           (d.getSeconds());
document.write(date);

更多的關(guān)于時(shí)間戳的可以參考這篇文章 http://chabaoo.cn/article/278265.htm

到此這篇關(guān)于js中 new Date().getTime()得到的是毫秒數(shù)時(shí)間戳的文章就介紹到這了,更多相關(guān)js時(shí)間戳內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論