Help us understand the problem. What is going on with this article?

js-cookieのexpires(有効期限)を細かい単位で設定する

More than 3 years have passed since last update.

Dateで計算する方法でもいけますが、
切りが良いタイミングで設定したい場合は日を単位にした数値でもOK👍

// 7日
Cookies.set('name', 'value', { expires: 7 });

// 半日
Cookies.set('name', 'value', { expires: 0.5 });
Cookies.set('name', 'value', { expires: 1/2 });

// 5分
Cookies.set('name', 'value', { expires: 5/1440 });

//10秒
Cookies.set('name', 'value', { expires: 10/86164});

公式wikiがあります。

js-cookie

pokkur
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away