C# 我可以对Azure Cosmos中的DateTimeOffset序列化对象使用DateTimePart函数吗?
我正试图使用DateTimePart函数对我的Cosmos数据库执行查询:C# 我可以对Azure Cosmos中的DateTimeOffset序列化对象使用DateTimePart函数吗?,c#,json,datetime,azure-cosmosdb,datetimeoffset,C#,Json,Datetime,Azure Cosmosdb,Datetimeoffset,我正试图使用DateTimePart函数对我的Cosmos数据库执行查询: SELECT c.callTime,c.id,c.source,DateTimePart('m', c.callTime) as month FROM c where c.ownerId='3467nm6df' 但在我的查询结果中,我在“月”字段中没有得到任何结果: { "callTime": "2020-09-30T20:17:28+00:00", "
SELECT c.callTime,c.id,c.source,DateTimePart('m', c.callTime) as month FROM c where c.ownerId='3467nm6df'
但在我的查询结果中,我在“月”字段中没有得到任何结果:
{
"callTime": "2020-09-30T20:17:28+00:00",
"id": "352hyKL5agNtB4ic",
"source": "five9"
}
我的cosmos数据库中的文档结构如下:
public class CallIndex
{
public string id;
public DateTimeOffset callTime;
public string source;
}
{
"callTime": "2020-09-30T20:17:32+00:00",
"id": "352WMvL5agNwiU7u",
"source": "five9"
},
{
"callTime": "2020-09-30T20:17:28+00:00",
"id": "352hyKL5agNtB4ic",
"source": "five9"
},
{
"callTime": "2020-09-30T20:16:51+00:00",
"id": "352iS3L5agN4yAog",
"source": "five9"
}
一些示例数据如下所示:
public class CallIndex
{
public string id;
public DateTimeOffset callTime;
public string source;
}
{
"callTime": "2020-09-30T20:17:32+00:00",
"id": "352WMvL5agNwiU7u",
"source": "five9"
},
{
"callTime": "2020-09-30T20:17:28+00:00",
"id": "352hyKL5agNtB4ic",
"source": "five9"
},
{
"callTime": "2020-09-30T20:16:51+00:00",
"id": "352iS3L5agN4yAog",
"source": "five9"
}
在做一些研究时,我发现有关Azure Csosmos中对DateTimeOffset
类型支持的信息存在冲突。在一些文章中,有人指出Cosmos支持DateTimeOffset
。在其他文章中,有人指出Cosmos不支持DateTimeOffset
,我应该使用DateTime
我们已经在代码中使用了DateTimeOffset
。在我们尝试上面的查询之前,它实际上工作得很好。我们以UTC存储所有内容,并在代码中使用DateTimeOffset
,以便在报告中轻松转换为客户端时区。所以我的问题是,函数DateTimePart
是否支持格式2020-09-30T20:16:51+00:00
(带偏移量的ISO日期时间)?或者,DateTimePart
是否仅适用于以下格式:2020-09-30T20:16:51.000000Z
(ISO日期时间格式)
如果后者为真,则需要将所有现有数据转换为ISO 8061日期时间格式,而不是带有偏移量的ISO 8061日期时间格式。如果我们最终这样做了,我如何告诉Newtonsoft如何将DateTimeOffset对象呈现为ISO 8061 DateTime(无偏移量)?是的。Azure Cosmos DB中日期时间字符串的推荐格式为yyyy-MM-ddTHH:MM:ss.FFFFFZ,该格式遵循标准。您上面显示的格式无法与查询中的DateTime系统函数一起使用。谢谢。关于将我的DateTimeOffset对象格式化为那种格式有什么建议吗?你能尝试使用这种格式吗?