0

I'm working on an application which get a date from a database by a web service and I can't change the web service. I made the following code to parse the date that I received in UTC and must be automatically convert to local time zone using Moment.js.

function convertDateToLocal(date) {
   return moment(date + " +0000", 'YY-MM-DD HH:mm:ss Z').toDate();
}

// Return the date in the appropriate format
  $scope.gpsDate = function(newDate){
    if(typeof newDate !== "undefined"){
        var date = convertDateToLocal(newDate);
        return date.toLocaleDateString()+ " " + date.toLocaleTimeString();
    }
    else
        return "/";
};

It works perfectly when I test it on Chrome on my computer but when I run it on my mobile it give the date on the following type : Friday, May 08, 2015. And I want 08/05/15. Is there anyone who can explain me where is the trouble please?

  • Think your problem is with toLocaleDateString() http://stackoverflow.com/questions/17459697/tolocaledatestring-javascript-date-format-issues – cYrixmorten May 08 '15 at 12:20
  • Maybe try and let angular handle date formatting http://stackoverflow.com/questions/20131553/angularjs-convert-dates-in-controller – cYrixmorten May 08 '15 at 12:22

0 Answers0