E
E
Eugene M.2020-05-06 07:24:01
JavaScript
Eugene M., 2020-05-06 07:24:01

How to transform the correct date in JS?

Hello! Tell me how to correctly write the date in cookies so that it turns out for 1 day, now this entry is not very clear to me (var ms = days*24*60*60*1000;) and for what period of time does it work!?

function setDefaultCookieExpire(days) {
    // transform days to milliseconds
    var ms = days*24*60*60*1000;

    var date = new Date();
    date.setTime(date.getTime() + ms);

    return "; expires=" + date.toUTCString();
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-05-06
@Seasle

Дни * Часы * Минуты * Секунды * Миллисекунды. And the number of days you have as a parameter comes.

F
Fenion, 2020-05-06
@Fenion

Recording

days*24*60*60*1000
converts number of days to milliseconds.
It is valid for the number of days specified when calling the function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question