この記事では、Time Format Output FormatDate関数のJavaScriptの実装について説明します。参照のためにそれを共有してください。詳細は次のとおりです。
JavaScriptは、FMTタグのようなDateTimeコンテンツ形式を入力する関数を提供しません。
以下は私の時間出力関数で、タグに直接配置され、使用されたときに呼び出されます。コードは次のとおりです
次のようにコードをコピーします:date.prototype.format = function(fmt){//著者:meizz
if(this == "無効な日付"){
戻る "";
}
var o = {
「M +」:this.getMonth() + 1、//月
「D+」:this.getDate()、// day
「H+」:this.gethours()、// hours
「M+」:this.getMinutes()、// min
「S+」:this.getSeconds()、// sec
「Q +」:math.floor((this.getMonth() + 3) /3)、// Quarterly
「S」:this.getMilliseConds()
// millisecond
};
if(/(y+)/.test(fmt))
fmt = fmt.Replace(regexp。$ 1、(this.gettlyear() + "")
.substr(4 -regexp。$ 1.Length));
for(o in o)
if(new regexp( "(" + k + ")")。test(fmt)))
fmt = fmt.Replace(regexp。$ 1、(regexp。$ 1.length == 1)?(o [k]))
:(( "00" + o [k])。substr(( "" + o [k])。長さ)));
FMTを返します。
}
使用するときは直接使用します
コードを次のようにコピーします:new Date(Time Variable).Format( "yyyy-mm-dd hh:mm:ss")
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。