Reputation: 11201
I am trying to get today's date with some specific format:
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 );
This is not working. What is the proper way of changing my date's format?
Upvotes: 2
Views: 1888
Reputation: 61812
In JavaScript, the months are zero based. For example:
January = 0
February = 1
...
Simply add one to your month:
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 );
Here's a working fiddle.
Upvotes: 3