AggregateCommand.dateFromParts(value: any): Object
聚合操作符。给定日期的相关信息,构建并返回一个日期对象。
参数
value: any
返回值
Object
API 说明
语法如下:
db.command.aggregate.dateFromParts({
year: <year>,
month: <month>,
day: <day>,
hour: <hour>,
minute: <minute>,
second: <second>,
millisecond: <ms>,
timezone: <tzExpression>
})
你也可以使用 ISO 8601 的标准:
db.command.aggregate.dateFromParts({
isoWeekYear: <year>,
isoWeek: <week>,
isoDayOfWeek: <day>,
hour: <hour>,
minute: <minute>,
second: <second>,
millisecond: <ms>,
timezone: <tzExpression>
})
示例代码
const $ = db.command.aggregate
db
.collection('dates')
.aggregate()
.project({
_id: 0,
date: $.dateFromParts({
year: 2017,
month: 2,
day: 8,
hour: 12,
timezone: 'America/New_York'
}),
})
.end()
输出如下:
{
"date": ISODate("2017-02-08T17:00:00.000Z")
}