Returning Invalid date in IOS for angularjs project when date is from different timezone

I’m working on an ionic angularJS project.

The date is returning from the database is like “2016-10-12T00:00:00.000+0200” (UTC+2 timezone)

I’m setting this to date field (Input type date) by changing the value as follows.

 $scope.datevalue = new Date($scope.datevalue); 

The above statement is working in android and returning Indian timezone as “Wed Oct 12, 2016, 03:30:00 GMT+0530 (India Standard Time)” But not working in IOS and returning “Invalid Date”

Could you please give me a solution for this?


You can use moment.js for resolving this. First import moment.js in your js library then write following code.

            if($scope.datevalue !== null){
                $scope.datevalue =  new Date(moment($scope.datevalue));

It should work

Leave a Reply

Your email address will not be published. Required fields are marked *