Javascript 无法设置cookie的过期日期
我正在用Javascript 无法设置cookie的过期日期,javascript,django,cookies,request,Javascript,Django,Cookies,Request,我正在用ReactJS和Djangowebapi开发一个web应用程序。我的问题是: 我向API发送一个请求,该请求返回一个令牌,我将使用该令牌发送需要身份验证的请求,以及令牌的过期日期 答案是这样的: { name: "Elliot", id: 1, token: "<the token here>" expires: "2018-04-29T17:00:00.000Z" } 它将失效日期设置为1969年。有人知道为什么吗 详情: 我看了看日期是否已经过
ReactJS
和Django
webapi开发一个web应用程序。我的问题是:
我向API发送一个请求,该请求返回一个令牌,我将使用该令牌发送需要身份验证的请求,以及令牌的过期日期
答案是这样的:
{
name: "Elliot",
id: 1,
token: "<the token here>"
expires: "2018-04-29T17:00:00.000Z"
}
它将失效日期设置为1969年。有人知道为什么吗
详情:
- 我看了看日期是否已经过期,但是,它没有过期。从现在起,总有3个小时
- 问题解决了!我认为日期的格式是对的,但事实并非如此。然后,我使用
toutString()
转换了日期,如下所示:
const expires = new Date(response.expires)
document.cookie = `token=${response.token};expires=${expires.toUTCString()}`
希望它能帮助别人
const expires = new Date(response.expires)
document.cookie = `token=${response.token};expires=${expires.toUTCString()}`