2015-03-24 8 views
-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(); 
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

код написан на JavaScript, а не Java. – Brian

+0

Можете ли вы поместить 4 пробела в начале каждой строки? Это упростило бы чтение кода. – Brian

ответ

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); 
Смежные вопросы