I am trying to write javascript code to format the date as I want, but I have problems working on Firefox (it works the way I want in Chrome).
The input that I have is 05/01/13 (mm / dd / yy) and I want 2013-05-01 (yyyy / mm / dd).
For this, I did something like this:
var formDate = document.getElementById("start").value; var myDate = new Date(formDate); var startDate = new Date(); startDate.setMonth(myDate.getMonth() + 1); startDate.setFullYear(myDate.getFullYear()); var FormattedDate = startDate.getFullYear() + "-" + ((startDate.getMonth() <= 10) ? "0" : "") + startDate.getMonth() + "-01";
You can try it in both browsers here: http://jsfiddle.net/j4BLH/
In Google Chrome, this code gives me, for example, 2013-05-01 in May, but in Firefox I have 1913-05-01 .
I know I could write something like "20" + startDate.getYear() , but I was wondering why the results are different from Chrome for Firefox? And maybe if you have a better way to write the code that I inserted here, let me know :)
Thanks!
source share