GetCurrentDateTime (Azure Cosmos DB)GetCurrentDateTime (Azure Cosmos DB)

适用于: SQL API

以 ISO 8601 字符串形式返回当前 UTC(协调世界时)日期和时间。Returns the current UTC (Coordinated Universal Time) date and time as an ISO 8601 string.


GetCurrentDateTime ()

返回类型Return types

YYYY-MM-DDThh:mm:ss.fffffffZ 格式返回当前 UTC 日期和时间 ISO 8601 字符串值,其中:Returns the current 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


GetCurrentDateTime() 是非确定性的函数。GetCurrentDateTime() is a nondeterministic function. 返回的结果为 UTC。The result returned is UTC. 精度为 7 位,准确度为 100 纳秒。Precision is 7 digits, with an accuracy of 100 nanoseconds.


此系统函数不会使用索引。This system function will not utilize the index. 如果需要将值与当前时间进行比较,请在查询执行之前获取当前时间,并在 WHERE 子句中使用该常量字符串值。If you need to compare values to the current time, obtain the current time before query execution and use that constant string value in the WHERE clause.


以下示例演示如何使用 GetCurrentDateTime() 内置函数获取当前 UTC 日期时间。The following example shows how to get the current UTC Date Time using the GetCurrentDateTime() built-in function.

SELECT GetCurrentDateTime() AS currentUtcDateTime

下面是示例结果集。Here is an example result set.

  "currentUtcDateTime": "2019-05-03T20:36:17.1234567Z"

后续步骤Next steps