May 20, 2021 WeChat Mini Program Development Document
Construct a reference to the service-side time. Can be used to query criteria, update field values, or add field values when records are added.
The method signature is as follows:
function serverDate(options?: object): ServerDate
The method accepts an optional object parameter option, whose fields are defined as follows:
The field name | Type | Required | The default | Description |
---|---|---|---|---|
offset | number | Whether | The referenced service-side time offset, in milliseconds, can be positive or negative |
The sample code
Set the field to service-side time when new records are added:
const db = wx.cloud.database()
db.collection('todos').add({
description: 'eat an apple',
createTime: db.serverDate()
})
The update field is one hour after the service side time:
const db = wx.cloud.database()
db.collection('todos').doc('my-todo-id').update({
due: db.serverDate({
offset: 60 * 60 * 1000
})
})
``