Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  93] [ 1]  / answers: 1 / hits: 19511  / 13 Years ago, tue, november 1, 2011, 12:00:00

I have a senario where i have to parse two dates for example start date and end date.



var startdate = '02/01/2011';
var enddate = '31/12/2011';


But if we alert start date



 alert(Date.Parse(startdate)); i will get 1296498600000


but if i alert enddate



 alert(Date.Parse(enddate)); i will get NaN


But this is working in other browsers except Chrome, But in other browsers



alert(Date.Parse(enddate)); i will get 1370889000000


Can anybody know a workaround for this?


More From » jquery

 Answers
17

If you want to parse a date without local differences, use the following, instead of Date.parse():



var enddate = '31/12/2011'; //DD/MM/YYYY
var split = enddate.split('/');
// Month is zero-indexed so subtract one from the month inside the constructor
var date = new Date(split[2], split[1] - 1, split[0]); //Y M D
var timestamp = date.getTime();


See also: Date


[#89348] Saturday, October 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kalynn

Total Points: 309
Total Questions: 105
Total Answers: 90

Location: Azerbaijan
Member since Fri, May 12, 2023
1 Year ago
;