簡體   English   中英

Angularjs在20分鍾內設置Cookies到期

[英]Angularjs Set Cookies expiration in 20 minutes

我想設置將在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});

我已經有了答案haha.i必須設置'date'變量以使用@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});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM