On this page本页内容
$dateToParts¶New in version 3.6.版本3.6中的新功能。
Returns a document that contains the constituent parts of a given BSON Date value as individual properties. 返回一个文档,该文档包含给定BSON Date值的组成部分,作为单个属性。The properties returned are 返回的属性为year, month, day, hour, minute, second and millisecond.year、month、day、hour、minute、second和millisecond。
You can set the iso8601 property to true to return the parts representing an ISO week date instead. This will return a document where the properties are isoWeekYear, isoWeek, isoDayOfWeek, hour, minute, second and millisecond.
The $dateToParts expression has the following syntax:$dateToParts表达式语法如下所示:
The $dateToParts takes a document with the following fields:$dateToParts采用带有以下字段的文档
| Required/Optional | ||
|---|---|---|
date |
Required |
|
timezone |
Optional |
|
iso8601 |
true, modifies the output document to use ISO week date fields. true,则修改输出文档以使用ISO周日期字段。false.false。 |
When using an Olson Timezone Identifier in the 在<timezone> field, MongoDB applies the DST offset if applicable for the specified timezone.<Timezone>字段中使用奥尔森时区标识符时,MongoDB会在适用于指定时区的情况下应用DST偏移量。
For example, consider a 例如,考虑带有以下文档的sales collection with the following document:sales集合:
The following aggregation illustrates how MongoDB handles the DST offset for the Olson Timezone Identifier. 下面的聚合说明了MongoDB如何处理Olson时区标识符的DST偏移量。The example uses the $hour and $minute operators to return the corresponding portions of the date field:
The operation returns the following result:操作返回以下结果:
Consider a 考虑一个sales collection with the following document:sales集合带有以下文档:
The following aggregation uses 以下聚合使用$dateToParts to return a document that contains the constituent parts of the date field.$dateToParts返回包含date字段组成部分的文档。
The operation returns the following result:操作返回以下结果: