時間、タイムスタンプの書式を設定します

1、時刻形式

関数getDayFormat(日){
    VARの年= date.getFullYear()+ ' - ' ;
   VAR月=((date.getMonth()+ 1)<10 +(date.getMonth()+ 1) '0':?(date.getMonth()+ 1))+ ' - ' ;
   VaRの日= date.getDate()<10?'0' + date.getDate():date.getDate();
   戻り年+月+ 
}

2、タイムスタンプ変換

  Date.prototype.Format = 関数(FMT){ // 著者:meizz 
            VAR O = {
                 "M +":この .getMonth()+ 1、                  // 月份 
                "D +":この .getDate()                     //  
                「H + 「:この .getHours()                    // 小时 
                "M +":この .getMinutes()                  //  
                "S +":この .getSeconds()                  //  
                "Q +":数学。床((この .getMonth()+ 3)/ 3)、// 季度 
                "S":この .getMilliseconds()              // 毫秒
            }。
            もし(/(Y +)/ .TEST(FMT))
                FMT = fmt.replace(正規表現$ 1、(。この .getFullYear()+ "").SUBSTR(4 -正規表現$ 1 .LENGTH))。
            VaRの K O)
                 であれば新しい正規表現( "(" + K + ")" ).TEST(FMT))
                    FMT = fmt.replace(正規表現。$ 1、(正規表現。$ 1.length == 1)?( O [K]):(( "00" + O [K])SUBSTR(( ""O [K])の長さ)))。
            リターンのfmt; 
        }。

用途:VAR時間=新しいDate( 'タイムスタンプ値').Format( "YYYY、MM-DD日HH:MM:SS"); //日付

おすすめ

転載: www.cnblogs.com/hellowoeld/p/10942929.html