Monday, 21 January 2019

Javascript date.setSeconds working as expected in Debugger but not in script

I have a function that sets a cookie as follows:

function createCookieWithDuration(name, value, duration) {
    const date = new Date();
    console.log(`date now: ${date}`);
    date.setSeconds(date.getSeconds() + duration);
    console.log(`adjusted date by ${duration} seconds: ${date}`);
    document.cookie = `${name}=${value}; expires=${date}; path=/`;
}

Now, if I do this line for line in the debugger it works as expected: enter image description here

But when I let the script run and log to the console I get 3 minutes added on as well as the seconds:

enter image description here

Is there a weird javascript timing thing that I'm missing here?



from Javascript date.setSeconds working as expected in Debugger but not in script

No comments:

Post a Comment