AI助手支持GPT4.0
云函数从数据库获得的时间错误?
数据库有个时间currtentTime,是通过db.serverDate()保存的。
问题如图。
记录时间明明是Thu Jul 30 2020 22:56:40 GMT+0800 (中国标准时间),取出就变成了2020-07-30T14:56:40.618Z。
使用getHours(),获得的就是14。
其他没有错,就是小时数不正确,不知道什么原因,请指教。
const cloud = require('wx-server-sdk')cloud.init()exports.main = async (event, context) => { const db = cloud.database() const query = await db.collection('support').doc(event.chatId).get() if (query) { let thisTime = query.data.chat[0].currtentTime return thisTime }}
The database has a time currenttime, which is passed through the db.serverDate () preserved. The problem is shown in the figure. The recording time is Thu Jul 30 2020 22:56:40 GMT + 0800 (China standard time), and the extracted time becomes 2020-07-30t14:56:40.618z. Using getHours (), you get 14. There is nothing wrong with the others, that is, the number of hours is not correct. I don't know why. Please advise me. const cloud = require('wx-server-sdk') cloud.init () exports.main = async (event, context) => { const db = cloud.database () const query = await db.collection ('support').doc( event.chatId ).get() if (query) { let thisTime = query.data.chat [0].currtentTime return thisTime }}
云函数中的时区为 UTC+0,不是 UTC+8,在云函数中使用时间时需特别注意。如果需要默认 UTC+8,可以配置函数的环境变量,设置
TZ
为Asia/Shanghai
。