SDK數(shù)據(jù)庫(kù) database·服務(wù)端時(shí)間的引用

2022-05-12 16:40 更新

Database.serverDate(options:Object): ServerDate

支持端:小程序 , 云函數(shù) , Web

構(gòu)造一個(gè)服務(wù)端時(shí)間的引用??捎糜诓樵儣l件、更新字段值或新增記錄時(shí)的字段值。

參數(shù)

options: Object

屬性類型默認(rèn)值必填說(shuō)明
offsetnubmer引用的服務(wù)端時(shí)間偏移量,毫秒為單位,可以是正數(shù)或負(fù)數(shù)

返回值

ServerDate

示例代碼

新增記錄時(shí)設(shè)置字段為服務(wù)端時(shí)間:

db.collection('todos').add({
  description: 'eat an apple',
  createTime: db.serverDate()
})

更新字段為服務(wù)端時(shí)間往后一小時(shí):

db.collection('todos').doc('my-todo-id').update({
  due: db.serverDate({
    offset: 60 * 60 * 1000
  })
})


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)