Question

I have an ISODateTime format :

2013-11-21T20:58:03+0000 

How to convert it to milliseconds in AngularJS.

I used DateTime.Parse() => it works on chrome but fails on ios. Any other way to implement the same?

My main aim for this is to find difference (in minutes) between current time and this time :

var diff= (new Date(new Date().getTime() - Date.parse(item['myDate']))).getMinutes();

where item['myDate'] = 2013-11-21T20:58:03+0000

Était-ce utile?

La solution

To be sure that it will work on any browser (like iOS safari) we can just split time and create new date instance.

Try:

$scope.item = {};   
$scope.item.myDate = '2013-11-21T20:58:03+0000';

var arr =  $scope.item.myDate.split(/[- :+T]/);
var fixedDate = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4]);

var currTime = new Date().getTime();
var fixedTime = fixedDate.getTime();
var tot = currTime -  fixedTime;

var minutes = tot / 1000 / 60;

console.log('tot', tot);
console.log('minutes', minutes);

Demo Fiddle

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top