我想用一些特定的格式来获取今天的日期:
var d = new Date();
var curr_year = d.getFullYear();
var curr_Month = d.getMonth();
var curr_date = d.getDate();
var todayDate = (curr_year +"/"+curr_Month +"/"+ curr_date );
这不起作用。更改日期格式的正确方法是什么?
答案 0 :(得分:3)
在JavaScript中,月份为零。例如:
1月= 0
二月= 1
...
只需在您的月份添加一个:
var d = new Date();
var curr_year = d.getFullYear();
var curr_Month = d.getMonth() + 1; // +1 to zero based month
var curr_date = d.getDate();
var todayDate = (curr_year +"/"+curr_Month+"/"+ curr_date );
答案 1 :(得分:3)
var curr_Month = d.getMonth() + 1; //months are zero based