ホームページ  >  記事  >  ウェブフロントエンド  >  javascriptの日付変換タイムスタンプから日付format_time and date

javascriptの日付変換タイムスタンプから日付format_time and date

WBOY
WBOYオリジナル
2016-05-16 17:59:341130ブラウズ
コードをコピー コードは次のとおりです。

Date.prototype.format = function(format)
{
var o =
{
"M " : this.getMonth() 1, //月
"d " : this.getDate(), //日
"h " : this .getHours(), //時間
"m " : this.getMinutes(), //分
"s " : this.getSeconds(), //秒
"q " : Math.floor ((this.getMonth() 3)/3), //四半期
"S" : this.getMilliseconds() //ミリ秒
}

if(/(y ) /.test (フォーマット))
{
format = format.replace(RegExp.$1, (this.getFull Year() "").substr(4 - RegExp.$1.length));

for(var k in o)
{
if(new RegExp("(" k ")").test(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 );//これはミリ秒の整数である必要があります
var testStr = testDate.format("yyyy year MM month dd日 hh 時 mm 分 ss 秒");
var testStr2 = testDate.format("yyyyMMdd hh:mm:ss");
alert(testStr " " testStr2);

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。