簡體   English   中英

如何在Jquery / Javascript中更改日期格式?

[英]How to change the date format in Jquery/Javascript?

如何在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):未捕獲RangeError:toString()基數參數必須在2到36之間

我將Phonegap用於我的android應用程序。

試試這個..

var d = new Date(); 
var newDate = d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear();

alert('newDate '+newDate);

您可以使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM