Date incrementing issue in bootstrap date picker

227 views Asked by At

I'm using bootstrap datepicker where the date when selected ,the ng-model $scope.taskInfo.startDate contains the selected date as Mon Jun 01 2015 00:00:00 GMT+0530 (India Standard Time)

ie., $scope.taskInfo.startDate = Mon Jun 01 2015 00:00:00 GMT+0530 (India Standard Time)

But when I perform date manipulation on my model,the date seems to jump one day behind.

$scope.taskInfo.startDate.toISOString() = "2015-05-31T18:30:00.000Z"

As you can see I selected June 1 2015,but it got changed to May 31 2015.Has anyone faced similar issue.Request you to share your thoughts

1

There are 1 answers

0
bitifet On BEST ANSWER

As explained in toISOString() documentation, this function returns the date (timestamp) in the zero UTC offset.

The timestamp you are providing is in the "India Standard" time zone. So that those two dates are representing the same exact moment, but one is showing the time at the Greendwich meridian and the other is showing the official time in the India Standard time zone which happen to be 5 hours and 30 minutes later.

Try to use .toString() instead, which will take care of your system configured time zone:

$scope.taskInfo.startDate.toString()