Home > database >  How to create a javascript date object with nodeJS
How to create a javascript date object with nodeJS

Time:03-03

res.cookie("cookieJWT", accessToken, {
  secure: false, 
  httpOnly: true,
  expires: // This needs a javascript date object, how do I create one for tomorrow?
});

Can plain nodeJS do this? Or do I need to download some modules?

CodePudding user response:

This would work if you mean 24 hours later by "tomorrow".

new Date(Date.now()   24 * 60 * 60 * 1000);

If you mean the beginning of tomorrow, you can do this. But note that the current timezone affects the result in this case.

const tomorrow = new Date(Date.now()   24 * 60 * 60 * 1000);
new Date(tomorrow.getFullYear(), tomorrow.getMonth(), tomorrow.getDate());
  • Related