AggregateCommand.dateFromParts(value: any): Object

支持端:小程序 2.7.4 起, 云函数 0.8.1

聚合操作符。给定日期的相关信息,构建并返回一个日期对象。

参数

value: any

返回值

Object

API 说明

语法如下:

  1. db.command.aggregate.dateFromParts({
  2. year: <year>,
  3. month: <month>,
  4. day: <day>,
  5. hour: <hour>,
  6. minute: <minute>,
  7. second: <second>,
  8. millisecond: <ms>,
  9. timezone: <tzExpression>
  10. })

你也可以使用 ISO 8601 的标准:

  1. db.command.aggregate.dateFromParts({
  2. isoWeekYear: <year>,
  3. isoWeek: <week>,
  4. isoDayOfWeek: <day>,
  5. hour: <hour>,
  6. minute: <minute>,
  7. second: <second>,
  8. millisecond: <ms>,
  9. timezone: <tzExpression>
  10. })

示例代码

  1. const $ = db.command.aggregate
  2. db
  3. .collection('dates')
  4. .aggregate()
  5. .project({
  6. _id: 0,
  7. date: $.dateFromParts({
  8. year: 2017,
  9. month: 2,
  10. day: 8,
  11. hour: 12,
  12. timezone: 'America/New_York'
  13. }),
  14. })
  15. .end()

输出如下:

  1. {
  2. "date": ISODate("2017-02-08T17:00:00.000Z")
  3. }