I have a date which is provided as a string such as 09/12/2012.
If the string is today, I wish to display “Today”, else I wish to display 09/12/2012.
The problem with my approach shown below is that a month like 09 gets parsed to 0 and not 9.
What is the best way to do this? Thank you
var currentDate = new Date();
dateText='09/12/2012';
var a=dateText.split('/');// mdY
$("#date").text(((parseInt(a[0])-1==currentDate.getMonth()&&parseInt(a[1])==currentDate.getDate()&&parseInt(a[2])==currentDate.getFullYear())?'Today':dateText));
Pass a second argument to
parseInt()– specifically, 10.The second argument tells the function the base to use for interpreting the expression. If you don’t pass that explicitly, it uses the old C conventions, which will lead to numbers starting with a zero to be interpreted as base 8 constants. That causes problems for
08and09.