[英]Get javascript cookie expiry value in minutes
I am using js-cookie to set a cookie with a 1 hour expiry like so:我正在使用 js-cookie 设置一个 1 小时到期的 cookie,如下所示:
const cookieExpiry = new Date( new Date().getTime() + 60 * 60 * 1000 );
const newCookie = Cookies.set("apiKey", "apiKeyFakeValue123456", { expires: cookieExpiry });
How would I check age of cookie is equal to or greater than 60m?我如何检查 cookie 的年龄是否等于或大于 60m?
My best attempt (not even grabbing expiry value from the time it was set:):我最好的尝试(甚至没有从设置时获取到期值:):
if (newCookie.getTime >= 60){ return someFunction();}
Many thanks in advance:)提前谢谢了:)
Barmar answered the question with: if (Cookies.get("apiKey")) Barmar 回答了这个问题:if (Cookies.get("apiKey"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.