1

Jquery/Javascriptで日付形式を変更するには?

date.jsをダウンロードし ました。次に、以下の例に従います。

var d1 = Date.parse('2010-10-18, 10:06 AM');
alert(d1.toString('dd/mm/yyyy HH:mm:ss GMT'));

だから私は次の日付のために自分のコードを書きます:

2013 年 1 月 31 日木曜日 16:29:30 GMT+0700 (WIT)

var d1 = Date.parse("Thu Jan 31 2013 16:29:30 GMT+0700 (WIT)");
alert(d1.toString('dd/mm/yyyy'));

私のlogcatはこれを出力します:

CordovaLog(31455): Uncaught RangeError: toString() 基数引数は 2 から 36 の間でなければなりません

Android アプリケーションに Phonegap を使用しています。

4

2 に答える 2

-1

JavaScript を使用して日付と時刻をフォーマットできます。http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3

function formatDate(date) {
    var d1 = Date.parse(date);
    var d = new Date(d1);
    var curr_date = d.getDate();
    if (curr_date.toString().length == 1) {
        curr_date = "0" + curr_date;
    }
    var curr_month = d.getMonth();
    curr_month++;
    if (curr_month.toString().length == 1) {
        curr_month = "0" + curr_month;
    }
    var curr_year = d.getFullYear();
    console.log(curr_date + "/" + curr_month + "/" + curr_year);
}

formatDate("Thu Jan 31 2013 16:29:30 GMT+0700 (WIT)");
//Returns the date in "dd/mm/yyyy" format
于 2013-02-06T09:38:49.450 に答える