[英]How to change the date format in Jquery/Javascript?
How to change the date format in Jquery/Javascript? 如何在Jquery / Javascript中更改日期格式?
I've downloaded the date.js . 我已经下载了date.js。 Then, I follow below example:
然后,我遵循以下示例:
var d1 = Date.parse('2010-10-18, 10:06 AM');
alert(d1.toString('dd/mm/yyyy HH:mm:ss GMT'));
So I write my own code for following date: 因此,我为以下日期编写了自己的代码:
Thu Jan 31 2013 16:29:30 GMT+0700 (WIT)
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'));
My logcat prints this: 我的logcat打印此:
CordovaLog(31455): Uncaught RangeError: toString() radix argument must be between 2 and 36
CordovaLog(31455):未捕获RangeError:toString()基数参数必须在2到36之间
I use Phonegap for my android application. 我将Phonegap用于我的android应用程序。
try out this.. 试试这个..
var d = new Date();
var newDate = d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear();
alert('newDate '+newDate);
You can use JavaScript to format date and time. 您可以使用JavaScript格式化日期和时间。 http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3
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.