LoginSignup
9
9

More than 5 years have passed since last update.

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

Posted at

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

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9