let sd = 1498482000000;
let serverDate = () => new Date() > sd ? (
new Date() - (new Date() - sd)
) : (
new Date() + (sd - new Date())
)
console.log(serverDate()) // 1498482000000
巴扎黑2017-06-28 09:29:55
Every time new Date()
will get a different value, and the calculation will take time, it is recommended to use now
cache: const now = new Date()
now - (now - sd)
, the expansion is now - now + sd
, that is, now + (sd - now)
, so the expressions of the two branches are equivalent, there is no need to write them at all Branch
Finally it can be omitted into one sentence: new Date(sd)
is the server time, why bother so much