Skip to content Skip to sidebar Skip to footer

Parsing Dates Using Localtimezone To Date Object In Javascript

I want to parse a date into a javascript date object. I am using the following new Date(Date.parse('2012-08-01')) The problem is my input date can be in multiple formats and parsi

Solution 1:

Replace the dashes with forward slashes and it will use the local time. Be sure to use yyyy/mm/dd ordering if you want it to work everywhere.

You also do not need to explicitly call Date.parse. The Date constructor will do that when you pass a string.

newDate('2012/08/01')  // localnewDate('2012-08-01')  // UTC

Yes, JavaScript is weird.

Post a Comment for "Parsing Dates Using Localtimezone To Date Object In Javascript"