java - 如何将日期时间字段保存到cosmosdb "SQL API/DocumentDb"?

标签 java azure azure-cosmosdb azure-cosmosdb-sqlapi

我将 DateTime 字段从 Java 发送到 documentdb/SQL API 到 cosmos db 。 但它将日期时间保存为 documentdb 中的数字,如果我将日期时间值解析为字符串,则 documentdb 将以字符串形式正确显示,但我需要在 documentdb/SQL API 中以日期时间格式显示它。

在 documentdb 中保存日期时间值而不将其解析为字符串的最佳实践是什么? 如果我不将日期时间字段解析为字符串,documentdb 集合中日期字段的值是多少?例如 "loggedAt": 1554207604392 在 documentdb 中显示此数字。谁能帮我解决这个问题。

Document Db Item, highlighted field is the datetime which i am sending from java

最佳答案

What is the value of the date field in the documentdb collection if i not parse my datetime field to string ?

该数字代表自 1970 年 1 月 1 日以来经过的秒数,它与 Unix 时间戳 的数据时间相匹配。 Azure Cosmos DB 的内部时间戳 (_ts) 属性遵循此方法。你可以引用这个document了解详情。

enter image description here

What's the best practise to save datetime value in documentdb without parsing it to string?

来自此反馈 case ,ms不支持原生datetime类型数据。在此blog ,日期时间数据仍然被视为字符串或数字。

对于unix时间戳查询操作,可以按照我之前的案例:Convert TimeScript to Date in Azure CosmosDB SQL Query使用 UDF 将 unix 时间戳转换为日期时间。或者从这个案例中得到一些线索:Date Between Query in Cosmos DB

关于java - 如何将日期时间字段保存到cosmosdb "SQL API/DocumentDb"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55474865/

相关文章:

azure - 是否可以通过 ARM 模板在 Azure SQL 中配置非管理用户?

azure - 如何在 CosmosDB SqlAPI 中使用破折号查询属性?

azure - 使用 dt.exe 命令行进行 Cosmosdb 迁移

azure - 用户定义函数在 documentdb 中不再起作用

java - 如何在 Android Studio 中实现折叠文本?

java - 从 SQlite 检索 URL 图像

Java Spring 基于 token 对用户进行身份验证

java - 在线免费 OPC 服务器用于测试和调试

azure - 可以将 ClickOnce 直接发布到 Azure Blob 存储吗?

azure-cosmosdb - Azure Cosmos DB JavaScript SDK 版本 1.x - 已弃用或无法使用?