iphone不支持(格式:2016-02-26 09:12)的格式时间需要转换成:(格式:2016/02/26 09:12)

function strToTime(str) {return Date.parse(str.replace(/-/g, "/"));}

 苹果手机不支持创建这种时间格式 需要转化一下; 

function getSpecialTimeStr(str) {
    var targetTime = this.strToTime(str);
    if (!targetTime) {
        return false;
    }
    var currentTime = new Date().getTime();
    var tdoa = Number(currentTime - targetTime),
        dayTime = 24 * 60 * 60 * 1000, // 1天
        hourTime = 60 * 60 * 1000, // 1小时
        minuteTime = 60 * 1000; // 1分钟

    if (tdoa >= dayTime) { // 天
        var h = tdoa / dayTime;
        if (h > 2) {
            return this.timeToString(targetTime);
        } else if (h > 1) {
            return '前天';
        } else {
            return '昨天';
        }
    } else if (tdoa >= hourTime) { // 小时
        return Math.floor(tdoa / hourTime) + '小时前';
    } else if (tdoa >= minuteTime) {
        return Math.floor(tdoa / minuteTime) + '分钟前';
    } else {
        return '最新';
        // return Math.floor(tdoa / 1000) + '秒前';
    }
}

  

原文地址:https://www.cnblogs.com/chengfeng6/p/6737589.html