假设需求为:在当天晚上0:00过期。

方法:

得到当天晚上0:00这个时间点的一个时间。

 function getNextDate(){
        var d = new Date(),
            year = d.getFullYear(),
            month = d.getMonth(),
            day = d.getDate(),
            nextDay = new Date( year, month, ( day + 1 ), 00, 00, 00 );

            return nextDay;
    },

接下来是设置cookie:

$.cookie("someKey", "someVal", {expires : getNextDate()});

备注:之前一直以为cookie只能设置以天为单位的数字,现在看来,也可以设置一个date类型的对象

相关文章:

  • 2021-06-21
  • 2021-11-15
  • 2021-12-01
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
相关资源
相似解决方案