微信小程序云开发服务端数据库API 构造一个服务端时间的引用


本文整理自网络,侵删。

db.serverDate

构造一个服务端时间的引用。可用于查询条件、更新字段值或新增记录时的字段值。

方法签名如下:

function serverDate(options?: object): ServerDate

方法接受一个可选对象参数 options,其字段定义如下:

字段名类型必填默认值说明
offsetnumber引用的服务端时间偏移量,毫秒为单位,可以是正数或负数

示例代码

新增记录时设置字段为服务端时间:

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  try {
    return await db.collection('todos').add({
      description: 'eat an apple',
      createTime: db.serverDate()
    })
  } catch(e) {
    console.error(e)
  }
}

更新字段为服务端时间往后一小时:

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  try {
    return await db.collection('todos').doc('my-todo-id').update({
      due: db.serverDate({
        offset: 60 * 60 * 1000
      })
    })
  } catch(e) {
    console.error(e)
  }
}
``



标签:微信小程序

相关阅读 >>

微信小程序 getvisitpage

微信小程序 服务市场invokeservice

微信小程序 拓展接口

微信小程序云开发数据库

微信小程序 运力方使用oncancelauth

微信小程序云开发api 更新多条记录

微信小程序 数据分析

微信小程序 getpaidunionid

微信小程序特有页面间传参方式

微信小程序api nfc-发送nfc消息

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...