【发布时间】:2020-09-28 17:26:50
【问题描述】:
当我在数据库中保存一些提醒时,我正在开发一个应用程序。下面是这个函数的代码sn-p:
const createNewSmsReminder = (textBody, dateTime) => {
console.log(dateTime)
let body = {
'content' : "This is a test",
'when' : dateTime
}
saveNewReminderAction(urlParams.uuid, body)
}
调用 saveNewReminderAction:
export const createNewSmsReminderAction = (uuid, body) => (dispatch) => {
dispatch({type: CREATE_NEW_SMS_REMINDER_PENDING})
fetch(config.url.API_URL+'/api/subscription/'+uuid+'/reminder', p_authorisation('POST', body))
.then(response=> response.json())
.then(data => dispatch({type: CREATE_NEW_SMS_REMINDER_SUCCESS, payload: data}))
.catch(error => dispatch({type: CREATE_NEW_SMS_REMINDER_ERROR, payload: error}))
}
在 createNewSms console.log(dateTime) 返回:
Mon Sep 28 2020 13:04:42 GMT-0400 (Eastern Daylight Time)
但当我观察请求的有效负载时,我注意到时间戳已转换为 UTC 格式:
{
content: "This is a test",
when: "2020-09-28T17:04:42.158Z"
}
这种正常行为是由 fetch/chrome/其他我什至想不到的东西强制执行的,还是我做错了什么?此外,如果这是正常的,它是否在不同的浏览器中保持一致,或者我希望将来会出现令人讨厌的惊喜?有没有办法强制执行? (值得一提的是,这正是我所追求的行为)
编辑:在这里回答以下问题是我的 p_authorisation 方法:
const p_authorisation = (method, body) => {
let auth = {
method: method,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Origin': '',
'Authorization': 'Bearer ' + localStorage.getItem('token'),
// 'skip_before_action' : 'verify_authenticity_token'
},
body: body ? JSON.stringify(body) : ''
}
return auth
}
【问题讨论】:
-
什么是
p_authorisation? -
我在原帖中添加了方法。
标签: javascript reactjs redux timezone timezone-offset