Jquery Date.parse returning NaN in Chrome browser?

前端 未结 2 1183
情话喂你
情话喂你 2020-12-03 21:07

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\';
         


        
2条回答
  •  孤街浪徒
    2020-12-03 21:59

    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

提交回复
热议问题