Date on iOS device returns NaN

I am currently developing an application based on cord paper with ionic and angular. Now I created a service that returns the formatted time the way my client wants it. The problem with this is that while it works on Android and in the browser, it displays NaN on the iOS device. Inserting the date I am from the database in the format timestamp: NOW (), is there a fix for this? this is my service date:

.factory('displaydate',['$filter', function($filter) {
  return function (date){
    var maandarray = new Array('Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'); 
    var actiondate = new Date(date);
    var today = new Date();
    if(today.getDate() == actiondate.getDate()){
        var hourssince =   today.getHours() - actiondate.getHours()
        var minutessince =   today.getMinutes() - actiondate.getMinutes()
        var secondssince =   today.getSeconds() - actiondate.getSeconds()
        if(hourssince > 0){
            date = hourssince+'u';
        }else if(minutessince > 0){
            date = minutessince+'m';
        }else{
            date = secondssince+'s';
        }
    }else{
        var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
        var diffDays = Math.round(Math.abs((today.getTime() - actiondate.getTime())/(oneDay)));
        if(diffDays > 28){
            var identifier = actiondate.getMonth() - 1;
            var month = maandarray[identifier];
            date = $filter('date')(actiondate,"d ") + month +  $filter('date')(actiondate," yy " + " HH:" + "mm");
        }else{ 
            date = diffDays+'d';
        }
    }
    return date;
  }
}]);
+6
source share
3 answers

This is fixed thanks to @Ian his comment,

changed this:

var actiondate = new Date(date);

:

var t = date.split(/[- :]/);

// Apply each element to the Date function
var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
var actiondate = new Date(d);
+22
source

, iPhone Safari Y-m-d H:i:s (ISO 8601). 2017/7/19, , Safari .

Sjoerd, Sjoerd, , . , ( Y-m-d H:i:s) , , iOS, .

function convertDateForIos(date) {
    var arr = date.split(/[- :]/);
    date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
    return date;
}

, ajax , , , .

+8


npm --save


= ( ).format()
var formatedDate = ()

,

-2

All Articles