当前位置: 首页 > 工具软件 > Infinity.js > 使用案例 >

js中Date和Infinity

卢深
2023-12-01

参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Infinity

例子:

const log = console.log;

log("begin ", Date.now() / 1000);
setTimeout(function() {
    log("last ", Math.floor(Date.now() / 1000));
}, 3000);

let d = new Date(1999, 11, 8, 14, 30, 44, 901);
log("d = ", d, ",    ", d.getTime() / 1000);
log("Date.now() = ", Date.now());
log(2 / 0);
log("Infinity === Infinity  ", Infinity === Infinity);
log("Infinity == Infinity  ", Infinity == Infinity);
log("Number.isFinite('xds')  ", Number.isFinite('xds'))
log("Number.isFinite('8x')  ", Number.isFinite('8x'))
log("Number.isFinite('80')  ", Number.isFinite('80'))
log("Number.isFinite(80)  ", Number.isFinite(80))
log("isFinite('xds')  ", isFinite('xds'))
log("isFinite('8x')  ", isFinite('8x'))
log("isFinite('80')  ", isFinite('80'))
log("isFinite(80)  ", isFinite(80))
log("8x" == 8)

结果:

$ node for.js
begin  1608522443.586
d =  1999-12-08T06:30:44.901Z ,     944634644.901
Date.now() =  1608522443598
Infinity
Infinity === Infinity   true
Infinity == Infinity   true
Number.isFinite('xds')   false
Number.isFinite('8x')   false
Number.isFinite('80')   false
Number.isFinite(80)   true
isFinite('xds')   false
isFinite('8x')   false
isFinite('80')   true
isFinite(80)   true
false
last  1608522446

 

 类似资料: