云函数从数据库获得的时间错误?

小程序 文章 2020-07-30 23:41 623 0 全屏看文

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  }}

回答:

Distance:

云函数中的时区为 UTC+0,不是 UTC+8,在云函数中使用时间时需特别注意。如果需要默认 UTC+8,可以配置函数的环境变量,设置 TZ 为 Asia/Shanghai

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
实名举报手机充值小程序虚拟支付可以正常使用?
微信公众号认证公账打款后,会退回么?
急!用国内营业执照开通的公众号,香港人可以当管理员/运营者吗?
能不能仿照qq搞个消息助手功能?有时候不想展示一些聊天
请问官方,小商店服务商上架的服务,一般要审核多久啊?
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8481
问题? 8002
如何快速搭建抽奖助手小程序(无需代码知识) 5263
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6533
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5826
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5488
如何解决渲染层网络错误Failed to load media? 16741
小程序找号找回 释放昵称? 2761
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 2629
删除部分微信用户个人数据的通知,怎么删除? 5800