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?