如何转换jquery日期格式

时间:2015-03-24 02:48:41

标签: java jquery

var d = new Date(recordDate[i].update_date);
var mnames = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "00");
var formattedDate = " ";
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
formattedDate = curr_date + "/" + mnames[curr_month] + "/" + curr_year;
console.log(new Date("formattedDate"));

1 个答案:

答案 0 :(得分:0)

您的脚本中有2个问题

var d = new Date(recordDate[i].update_date);
var mnames = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "00");
var formattedDate = " ";
var curr_date = d.getDate();
//since you are using array based month names, don't add 1 as array index start from 1
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
formattedDate = curr_date + "/" + mnames[curr_month] + "/" + curr_year;
//formattedDate is the formatted date, so no need to create a new date object
console.log(formattedDate);