javascript日期轉(zhuǎn)換 時間戳轉(zhuǎn)日期格式
更新時間:2011年11月05日 15:09:58 作者:
javascript日期轉(zhuǎn)換 時間戳轉(zhuǎn)日期格式實現(xiàn)代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
Date.prototype.format = function(format)
{
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o)
{
if(new RegExp("("+ k +")").test(format))
{
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
}
var testDate = new Date( 1320336000000 );//這里必須是整數(shù),毫秒
var testStr = testDate.format("yyyy年MM月dd日hh小時mm分ss秒");
var testStr2 = testDate.format("yyyyMMdd hh:mm:ss");
alert(testStr + " " + testStr2);
您可能感興趣的文章:
- js時間戳轉(zhuǎn)為日期格式的方法
- JavaScript 獲取當(dāng)前時間戳的代碼
- js時間戳與日期格式之間相互轉(zhuǎn)換
- javascript時間戳和日期字符串相互轉(zhuǎn)換代碼(超簡單)
- js時間戳格式化成日期格式的多種方法
- js 時間格式與時間戳的相互轉(zhuǎn)換示例代碼
- JS獲取當(dāng)前時間戳方法解析
- JS獲取時間的相關(guān)函數(shù)及時間戳與時間日期之間的轉(zhuǎn)換
- nodejs如何獲取時間戳與時間差
- Vue.js 時間轉(zhuǎn)換代碼及時間戳轉(zhuǎn)時間字符串
- js獲取時間并實現(xiàn)字符串和時間戳之間的轉(zhuǎn)換
- 時間戳轉(zhuǎn)換為時間 年月日時間的JS函數(shù)
- js實現(xiàn)把時間戳轉(zhuǎn)換為yyyy-MM-dd hh:mm 格式(es6語法)
- Javascript new Date().valueOf()的作用與時間戳由來詳解
- JavaScript時間戳與時間日期間相互轉(zhuǎn)換
- jsp頁面中如何將時間戳字符串格式化為時間標(biāo)簽
- js格式化時間和js格式化時間戳示例
- js中?new?Date().getTime()得到的是毫秒數(shù)時間戳
相關(guān)文章
JavaScript 腳本將當(dāng)?shù)貢r間轉(zhuǎn)換成其它時區(qū)
毫無疑問,用JavaScript腳本可以通過直接查看用戶的時鐘,方便地在網(wǎng)頁上顯示本地時間。2009-03-03
Javascript 倒計時源代碼.(時.分.秒) 詳細(xì)注釋版
基于js的倒計時實現(xiàn)代碼,并有詳細(xì)的注釋比較適合學(xué)習(xí)使用。2011-05-05

