如何在Jquery/Javascript中更改日期格式?
如何在Jquery/Javascript中更改日期格式 我已经下载了 . 然后,我遵循以下示例:如何在Jquery/Javascript中更改日期格式?,javascript,jquery,Javascript,Jquery,如何在Jquery/Javascript中更改日期格式 我已经下载了 . 然后,我遵循以下示例: 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) 我的logcat打印了这个: CordovaLog(31455):未捕获的RangeError:toStr
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)
我的logcat打印了这个:
CordovaLog(31455):未捕获的RangeError:toString()基数参数必须为
介于2和36之间
我在android应用程序中使用Phonegap。您可以使用JavaScript格式化日期和时间 试试这个
var d = new Date();
var newDate = d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear();
alert('newDate '+newDate);
试着用瞬间代替。它对于日期解析和格式化非常好,我认为momentjs是javascript中最接近JodaTime的。另一个选择是使用的日期格式化程序,但我认为momentjs更好。我对momentjs非常感兴趣,但文档非常长,我找不到任何方法将时间戳转换为格式化的date.moment(timestaminmilliss.format('DD/MM/yyyyy')
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
var d = new Date();
var newDate = d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear();
alert('newDate '+newDate);