我想设置将在 20 分钟后过期的 cookie。我可以设置一天设置。我该如何应对这种情况?
var date = new Date();
cookies.put("userName","My Name",{'expires':date.getDate()+1});
cookies.put("userNickName","My NickName",{'expires':date.getDate()+1});
cookies.put("userID","My ",{'expires':date.getDate()+1});
最佳答案
我已经有了答案哈哈。我必须使用@Suren Srapyan 提供的代码设置“日期”变量以增加 20 分钟,然后将其传递给 expires 属性。所以它会像这样
//declare date and get current date time
var date = new Date();
//add 20 minutes to date
date.setTime(date.getTime() + (20* 60 * 1000));
//pass the "date" variable to expires properity
cookies.put("userName","My Name",{'expires':date});
cookies.put("userNickName","My NickName",{'expires':date});
cookies.put("userID","My ",{'expires':date});
关于javascript - Angularjs 设置 Cookie 在 20 分钟内过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42134432/