ホームページ  >  記事  >  ウェブフロントエンド  >  js形式の時刻とjs形式のタイムスタンプの例_基礎知識

js形式の時刻とjs形式のタイムスタンプの例_基礎知識

WBOY
WBOYオリジナル
2016-05-16 17:00:491180ブラウズ

复制代代码如下:

/**
* 時間オブジェクトのフォーマット;
*/
日付.prototype.format = function(format) {
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
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 = format.replace(RegExp.$1, (this.getFull Year() "")
.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));
}
}
戻り形式;
}

复制代代码如下:

var now = new Date().format("yyyy -MM-dd hh:mm:ss");

复制代代码如下:

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