2017-02-09 84 views
0

我想設置將在20分鐘內過期的cookie。我可以設置一天的時間設置。我可以應對這種情況嗎?Angularjs在20分鐘內設置Cookies過期

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}); 

回答

0

我已經有了答案haha.i必須設置「日期」變量與@Suren Srapyan給代碼添加20分鐘,然後將它傳遞到期滿財產。所以它會是這樣

//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});