C
C
chebupelina2017-01-20 13:09:02
JavaScript
chebupelina, 2017-01-20 13:09:02

How to register that the cookie would be exhibited once an hour?

With this code, cookies are set once a day, but once an hour, as I understand it, what needs to be fixed here (days*24*60*60*1000), but I don’t know what exactly. Can you help me figure out what each number stands for?

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2017-01-20
@chebupelina

24 is the number of hours in a day. Just take 24 out of the total.
Then not days but hours will fall into the function. It would be better to rename days to hours, but not necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question