Hey so I am trying to set my express-session cookie maxAge, so it is giving me that deprecation warning.
So I see that I have to be using milliseconds however what I fail to achieve is how can I get the current date using milliseconds?
I looked at MDN Docs unless I did not understand I thought if I did this below as stated in docs(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds):
var today = new Date(); var milliseconds = today.getMilliseconds();
I thought this should give me the current date in milliseconds and this is from MDN
but when I parse the number given back to a date object I get the following date 1970-01-01T00:00:00.772Z
then once I saw this I knew for sure that I am not doing this the right way I tried Google searching and could not find solution can I please get help
Advertisement
Answer
today.getMilliseconds() will get you the the current seconds milliseconds so it resets every second. You need to use getTime() instead which returns milliseconds between 1 January 1970 00:00:00 and current time.
var today = new Date(); var milliseconds = today.getTime();