I'm having trouble correctly formatting two-digit dates as 4-digit dates.
I have an input text box:
<input type="text" value="" class="date"/>
And then I want to format it in the format "mm / dd / yyyy" after the user enters the date. Therefore, I have an onChange event:
$('.date').on('change',function(){ var date = new Date($(this).val()); $(this).val((date.getMonth()+1)+'/'+date.getDate()+'/'+date.getFullYear()); });
Ok, now weirdness comes (I will use 12/12/12 as an example):
1) getFullYear () returns 1912 in all IE, FF. Chrome returns in 2012.
2) getYear () returns 112 in IE, Chrome. FF returns 12.
Thus, it seems that the only option at the moment is to sniff the user agent and use it accordingly. Anyway, sniffs UA?
jkinz source share