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
Every time
new Date()
will get a different value, and the calculation will take time, it is recommended to usenow
cache:const now = new Date()
now - (now - sd)
, the expansion isnow - 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 BranchFinally it can be omitted into one sentence:
new Date(sd)
is the server time, why bother so much