谁能告诉我为什么在 Javascript 中这是由 Math.pow(10, 12) 或 1000000000000 而不是 Math.pow(10, 9) 或 1000000000 解决的。解决方案在 ruby 中如此清晰,在 JS 中如此混乱。我的 Js 解决方案:
var gigDate = Math.pow(10, 12);
function Gigasecond(dateIn) {
this.dateIn = dateIn
};
Gigasecond.prototype.date = function(){
return new Date(this.dateIn.getTime() + gigDate);
};
module.exports = Gigasecond;
Run Code Online (Sandbox Code Playgroud)
我的红宝石代码:
class Gigasecond
VERSION = 1
def self.from(date)
date + (10**9)
end
end
Run Code Online (Sandbox Code Playgroud)