我在Enter a list: [1,34,543,5,23,"apple"]
Enter another list: [54,23,6,213,"banana"]
True
Enter a list: [1,34,543,5,25,"apple"]
Enter another list: [54,23,6,213,"banana"]
False
中有一个时差的愚蠢问题。
获取时差的代码
moments.js
格式化秒的功能:
var to = '2019-02-03 01:55:00'; //When counter ends
var start = moment(); //Current time, for this example assume is '2019-02-03 01:53:00'
var end = moment(to);
var seconds = end.diff(start, 'seconds', true); //get difference in seconds, the third params is to get not rounded, but since in toMMSS function I do parseInt is useless
var formatted = toMMSS(seconds);
现在预期的输出为var toMMSS = function (seconds) {
var sec_num = parseInt(seconds, 10);
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
return minutes+':'+seconds;
};
,但是有些人会得到02:00
或02:05
或02:07
,但是02:03
-'2019-02-03 01:55:00'
的输出应该(在逻辑上)为'2019-02-03 01:53:00'
P.S。 moment.js默认值:
02:00
moment.tz.setDefault('Europe/Moscow');
moment.defaultFormat = "YYYY-MM-DD HH:mm:ss";
也在该时区。
我尝试了其他方法来计算差异,但是得到相同的结果,可能是在某些PC /浏览器上这不准确,如果可以,也许有一种解决方法不依赖用户PC时间?
任何帮助表示赞赏。