DateTimeFromParts (Azure Cosmos DB)DateTimeFromParts (Azure Cosmos DB)

适用于: SQL API

返回根据输入值构造的字符串 DateTime 值。Returns a string DateTime value constructed from input values.

语法Syntax

DateTimeFromParts(<numberYear>, <numberMonth>, <numberDay> [, numberHour]  [, numberMinute]  [, numberSecond] [, numberOfFractionsOfSecond])

参数Arguments

numberYear 年份的整数值,格式为 YYYYnumberYear Integer value for the year in the format YYYY

numberMonthnumberMonth
月份的整数值,格式为 MMInteger value for the month in the format MM

numberDaynumberDay
日期的整数值,格式为 DDInteger value for the day in the format DD

numberHour(可选)小时的整数值,格式为 hhnumberHour (optional) Integer value for the hour in the format hh

numberMinute(可选)分钟的整数值,格式为 mmnumberMinute (optional) Integer value for the minute in the format mm

numberSecond(可选)秒的整数值,格式为 ssnumberSecond (optional) Integer value for the second in the format ss

numberOfFractionsOfSecond(可选)表示秒的小数部分的整数值,格式为 .fffffffnumberOfFractionsOfSecond (optional) Integer value for the fractional of a second in the format .fffffff

返回类型Return types

YYYY-MM-DDThh:mm:ss.fffffffZ 格式返回 UTC 日期和时间 ISO 8601 字符串值,其中:Returns a UTC date and time ISO 8601 string value in the format YYYY-MM-DDThh:mm:ss.fffffffZ where:

格式Format 描述Description
YYYYYYYY 四位数的年份four-digit year
MMMM 两位数的月份(01 = 1 月,依此类推。)two-digit month (01 = January, etc.)
DDDD 两位数的月份日期(01 到 31)two-digit day of month (01 through 31)
TT 时间元素开头的符号signifier for beginning of time elements
hhhh 两位数的小时(00 到 23)two-digit hour (00 through 23)
MMmm 两位数的分钟(00 到 59)two-digit minutes (00 through 59)
ssss 两位数的秒(00 到 59)two-digit seconds (00 through 59)
.fffffff.fffffff 七位数的小数秒seven-digit fractional seconds
ZZ UTC(协调世界时)指示符UTC (Coordinated Universal Time) designator

备注Remarks

如果指定的整数将创建无效的 DateTime,则 DateTimeFromParts 将返回 undefinedIf the specified integers would create an invalid DateTime, DateTimeFromParts will return undefined.

如果未指定可选参数,则其值为 0。If an optional argument isn't specified, its value will be 0.

示例Examples

以下是仅包含构造 DateTime 所需的参数的示例:Here's an example that only includes required arguments to construct a DateTime:

SELECT DateTimeFromParts(2020, 9, 4) AS DateTime
[
    {
        "DateTime": "2020-09-04T00:00:00.0000000Z"
    }
]

以下是另一个示例,该示例还使用一些可选参数来构造 DateTime:Here's another example that also uses some optional arguments to construct a DateTime:

SELECT DateTimeFromParts(2020, 9, 4, 10, 52) AS DateTime
[
    {
        "DateTime": "2020-09-04T10:52:00.0000000Z"
    }
]

以下是另一个示例,该示例还使用所有可选参数来构造 DateTime:Here's another example that also uses all optional arguments to construct a DateTime:

SELECT DateTimeFromParts(2020, 9, 4, 10, 52, 12, 3456789) AS DateTime
[
    {
        "DateTime": "2020-09-04T10:52:12.3456789Z"
    }
]

后续步骤Next steps