标签:seconds div val exchange log pre androi gets 调试
后台下发的时间格式如:2016-09-15 15:30:10;
也没多想,直接用new Date(‘2016-09-15 15:30:10‘).getTime()获取时间戳;
开发时候,电脑调试OK,当放到触屏调试的时候,AndroidOK,但是ios也不行了,结果是:NaN-NaN1-NaN Invalid Date
what?
后面了解到:ios能读取的格式是:2016/09/15 15:30:10
好吧,那一写成转换时间戳的统一方法来调用:
exports.exchangeTime = function(date){ if(date){ //2016-09-15 15:30:10 var date_1 = date.split(‘ ‘)[0], date_2 = date.split(‘ ‘)[1]; var y = date_1.split(‘-‘)[0], m = date_1.split(‘-‘)[1], d = date_1.split(‘-‘)[2], h = date_2.split(‘:‘)[0], i = date_2.split(‘:‘)[1], s = date_2.split(‘:‘)[2]; }else{ var now_date = new Date(); var y = now_date.getFullYear(), m = now_date.getMonth() + 1, d = now_date.getDate(), h = now_date.getHours(), i = now_date.getMinutes(), s = now_date.getSeconds(); } return Date.UTC(y, m, d, h, i, s); }
标签:seconds div val exchange log pre androi gets 调试
原文地址:http://www.cnblogs.com/leaf930814/p/7527298.html