0

Hey guys, Im having trouble knowing wat is the correct date format i should put for date.parse() function.

I want to use mm/dd/yyyy in the function like this.

alert("Date: "+Date.parse("11/28/2011")); 
//-->Its showing me Date:NaN as output.

also I wanted to know what output should I be getting if I do this following code:

date = Date.parse('12/31/2011' +' UTC');
var minutes=1000*60;
var hours=minutes*60;
var days=hours*24;
var years=days*365;
var y=date/years;

t should give me exactly 42 years but its giving me decimal as well. Y so??

Any help will be appreciated guys.

Thanks

Anand

anand
  • 473
  • 5
  • 13
  • 24

2 Answers2

2

International (ISO) standard date time format will always work. 2011-12-31

You may also look at this and this

Community
  • 1
  • 1
Naveed Butt
  • 2,861
  • 6
  • 32
  • 55
  • 1
    Dunno about "universal", but it's an international (ISO) standard and certainly much more widely and consistently supported than the ambiguous format used by the OP. – RobG Mar 30 '11 at 07:25
  • Universal is too strong -- this doesn't work in IE6-8. See http://dygraphs.com/date-formats.html. In practice you'll have better luck using YYYY/MM/DD. – danvk Mar 14 '12 at 19:49
1

Why would it give you exactly 42 years? Don't forget that there's no such thing as an exact number of milliseconds in a year, due to leap years (and leap seconds, if they're accounted for). Even if there were, you're getting the start of the last day of 2011, which isn't the same as the start of the first day of 2012, which is probably what you were thinking of.

The exact formats supported are implementation-specific as far as I can tell - at least for ECMAScript (which I realise isn't quite the same as JavaScript).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • yea i was of the impression that exact days divided by 365 will give me exactly 42 yrs but as u rightly pointed out,that aint the case. – anand Mar 31 '11 at 04:18