我目前正在使用ionic和angularjs开发基于Cordova Web的应用程序。现在,我创建了一个服务,该服务以我的客户希望的方式返回格式化时间。.问题是,尽管它可以在android和浏览器上运行,但会在iOS设备上显示NaN。我插入的日期来自时间戳为NOW()的数据库,是否有针对此的解决方法?
这是我的约会服务:
.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;
}
}]);
最佳答案
通过@Ian的评论解决了此问题,
改变了这个:
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);
关于javascript - iOS设备上的日期返回NaN,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26657353/