nodatime 相关问题

Noda Time是一个.NET库,旨在简化.NET环境中日期和时间的正确处理。

EFCORE,NPGSQL和NODATIME将无效的例外读取Timestamptz瞬间从.NET 6到8

我们首先有一个现有的数据库(例如脚手架).NET 6项目附加到PostgreSQL 13 dB。 DB有很多Timestamptz aka时间戳,并带有时区字段。因此,我们使用nodatime。 时间(!)凸轮...

回答 0 投票 0


DurationPattern 在没有分隔符的情况下无法解析

我的任务是以“HHmm”格式表示持续时间。这至少名义上是 Nodatime.DurationPattern 解析起来应该没有问题的,因为它遵循

回答 1 投票 0

如何将NodaTime与redis结合使用?

我正在使用 .net 9 中的 HybridCahce 实现,并使用 DragonFly 实例作为分布式缓存,并按预期工作: builder.Services.AddStackExchangeRedisCache(选项 => opti...

回答 1 投票 0

aspnet razor 页面形成本地日期时间,不适用于 NodaTime LocalDateTime

我有一个输入类型为 local-datetime 的表单,需要以下格式的日期和时间: yyyy-MM-ddTHH:mm 默认情况下,NodaTime LocalDateTime 格式为 yyyy-MM-ddTHH:mm:ss a...

回答 2 投票 0

aspnet 表单与 nodatime 和输入本地日期时间的绑定问题

使用 LocalDateTime 时,NodaTime 和 aspnet 之间存在绑定问题 这是一个示例剃刀页面应用程序: 项目.csproj 使用 LocalDateTime 时,NodaTime 和 aspnet 之间存在绑定问题 这是一个示例剃刀页面应用程序: 项目.csproj <ItemGroup> <PackageReference Include="NodaTime" Version="3.1.12" /> <PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.2.0" /> </ItemGroup> 程序.cs builder.Services.AddRazorPages() .AddJsonOptions(o => o.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)); 索引.cs public class IndexModel : PageModel { [BindProperty] public LocalDateTime Local { get; set; } public void OnPost() { } } 索引.cs.cshtml <form method="post"> <input asp-for="Local" type="datetime-local" /> <button type="submit">Send</button> </form> 浏览器用于将数据发送回服务器的默认格式是yyyy-MM-ddTHH:mm,NodaTime 默认不支持。 NodaTime 期待 yyyy-MM-ddTHH:mm:ss 正常工作。 让 NodaTime 使用输入类型的最佳方式是什么 datetime-local 从 ConfigureForNodaTime(this JsonSerializerOptions options, DateTimeZoneProvider zoneProvider) 1.2.0 版本开始,您不仅可以调用 NodaTime.Serialization.SystemTextJson,还可以调用 ConfigureForNodaTime(this JsonSerializerOptions options, NodaJsonSettings nodaJsonSettings)。这使您可以执行更多配置。理想情况下,您会使用 LocalDateTimePattern.DateHourMinuteIso,但这尚未出现在 NodaTime 版本中 - 幸运的是您可以自己有效地创建它: var pattern = LocalDateTimePattern.CreateWithInvariantCulture("uuuu-MM-dd'T'HH:mm"); var nodaSettings = new NodaJsonSettings { LocalDateTimeConverter = new NodaPatternConverter<LocalTime>(pattern) }; builder.Services.AddRazorPages() .AddJsonOptions(o => o.JsonSerializerOptions.ConfigureForNodaTime(nodaSettings)); 此代码未经测试,但我期望它能够工作。 请注意,这将始终使用HH:mm解析和格式化值。如果您确实想在秒数存在时格式化为 HH:mm:ss,则需要更多工作,使用 CompositePatternBuilder<>。

回答 1 投票 0

无法使用NodaTime.TzdbCompiler生成NodaZoneData文件

当我尝试使用 NodaTime.TzdbCompiler 和最新的 IANA tzdb 下载生成 NodaZoneData 文件时,我收到以下输出: 开始编译目录数据�4f 解析

回答 1 投票 0

混合持续时间和本地时间数学

首先,NodaTime 似乎是一个经过深思熟虑、功能齐全的软件包,值得称赞。问题,也许我错过了一些东西,但是 Duration 是否可以与 LocalTime 混合?我需要做一些...

回答 1 投票 0

如何使用NodaTime.Tzdb获取当前区域

使用C#并使用NodaTime.Tzdb 我的目标是获取当前时区的区域 ID。 根据 https://nodatime.org/TimeZones,我当前的区域 ID 应该是 Europe/Copenhagen。 但我不确定...

回答 1 投票 0

在 noda 时间 LocalDate 和 Datetime 之间转换的最佳方式?

我在项目中同时使用原生日期时间和Noda时间库LocalDate。 LocalDate主要用于计算,而Datetime则用于其他地方。 有人可以...

回答 3 投票 0

EF Core NodaTime 字段 - 无法映射

我正在使用 EF Core 和 我刚刚向我的实体添加了一个 NodaTime.LocalDate 字段,您...

回答 2 投票 0

如何在 ASP.NET Core 6.0 Web API 中将 NodaTime Instant 配置为 LocalDateTime 序列化

我不知道如何将NodaTime的Instant数据类型转换为LocalDateTime,甚至更好地转换为System.DateTime。 我可以将 Instant 保存到 Postgresql 数据库,然后通过 Web 服务接收它。网络

回答 1 投票 0

有没有办法在 Npgsql EF Core 上检索时区后比较 LocalDate?

Nodatime 插件不支持参数化时区。我想创建一个自定义帮助器方法来执行下面代码的逻辑。我的 LINQ 无法翻译的原因是...

回答 1 投票 0

如何在NodaTime中为Instant添加年份?

从NodaTime的文档中我明白为什么ZonedDateTime或Instant上没有AddYear。然而,我需要某种方法来到达“明年的这个时候”(我需要的所有时间都存储/使用在...

回答 1 投票 0

如何在NodatTime中为Instant添加年份?

从NodaTime的文档中我明白为什么ZonedDateTime或Instant上没有AddYear。然而,我需要某种方法来到达“明年的这个时候”(我需要的所有时间都存储/使用在...

回答 1 投票 0

日期时间的 FluentValidation

我有以下代码行用于 PublishedDateTime 字段上的数据注释验证,但我想通过 FluentValidation API 进行验证 公共即时发布 { get;放; } [已过时(“EF-

回答 1 投票 0

将NodaTime转换为Unix时间戳以及LocalDateTime的重要性

我目前正在使用 NodaTime,因为我在 C# 的 DateTime 类中处理时区时遇到了挫折。到目前为止,我真的很高兴。 公共静态字符串 nodaTimeTest(字符串输入) { var 默认Va...

回答 1 投票 0

“JsonException:JSON 值无法转换为 NodaTime.Instant”ASP.NET Core 3.1 Razor Page Web 应用程序的 NodaTime 问题

在 ASP.NET Core 3.1 Razor Page 纯前端 Web 应用程序中,我收到以下错误。 安装了以下软件包: 在 ASP.NET Core 3.1 Razor Page 纯前端 Web 应用程序中,我收到以下错误。 安装了以下软件包: <PackageReference Include="System.Text.Json" Version="4.7.2" /> <PackageReference Include="EnumExtensions.System.Text.Json" Version="1.0.0" /> <PackageReference Include="NodaTime" Version="3.0.1" /> <PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.0.0" /> 也在启动中进行设置: services.AddRazorPages() .AddJsonOptions(options => { // options.JsonSerializerOptions.PropertyNamingPolicy = null; // options.JsonSerializerOptions.PropertyNameCaseInsensitive = true; // options.JsonSerializerOptions.DictionaryKeyPolicy = null; options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverterWithAttributeSupport(null, true, true, true, true)); //options.JsonSerializerOptions.IgnoreNullValues = true; options.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); options.JsonSerializerOptions.Converters.Add(NodaConverters.IntervalConverter); options.JsonSerializerOptions.Converters.Add(NodaConverters.InstantConverter); }) .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Login", ""); }); JsonException:JSON 值无法转换为 NodaTime.Instant。路径:$.data[0].created_at |行号: 0 |字节位置内联:261。 System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(类型 propertyType) System.Text.Json.JsonPropertyInfoNotNullable.OnRead(参考 ReadStack 状态,参考 Utf8JsonReader 阅读器) System.Text.Json.JsonPropertyInfo.Read(JsonTokenType tokenType,参考ReadStack状态,参考Utf8JsonReader阅读器) System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions选项,参考Utf8JsonReader阅读器,参考ReadStack readStack) System.Text.Json.JsonSerializer.ReadCore(类型 returnType,JsonSerializerOptions 选项,参考 Utf8JsonReader 阅读器) System.Text.Json.JsonSerializer.Deserialize(字符串json,类型returnType,JsonSerializerOptions选项) System.Text.Json.JsonSerializer.Deserialize(字符串json,JsonSerializerOptions选项) 这是它尝试反序列化的数据片段。如果我从 Instant 切换到 DateTimeOffset,它会“立即”工作。 { "data": [ { "created_at": "2020-08-09T22:10:26.274672Z", "updated_at": "2020-08-13T02:22:02.640871Z", } ], "page": 1, "size": 20, "count": 1, "total": 1, "success": true, "message": null } 注意:此 JSON 数据是对象序列化的结果,该对象包含 (NodaTime)Instant 类型的 CreatedAt 和 UpdatedAt 属性。我确认它与 ASP.NET Core 3.1 MVC API 应用程序配合良好。 不知道为什么它不起作用。 在当前版本的JsonSerializerOptions中,无法将System.Text.Json设置为全局。这可以通过在需要的地方构建选项来解决: var jsonString = "{\"data\":[{\"id\":\"f606942c-4740-46a7-be6f-66ceb38c530b\",\"created_at\":\"2020-08-09T22:10:26.274672Z\",\"updated_at\":\"2020-08-13T02:22:02.640871Z\"}],\"page\":1,\"size\":20,\"count\":1,\"total\":1,\"success\":true,\"message\":null }"; JsonSerializerOptions options = new JsonSerializerOptions(); options.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); options.Converters.Add(new JsonStringEnumConverterWithAttributeSupport(null, true, true, true, true)); var response = JsonSerializer.Deserialize<Response>(jsonString, options); public enum SampleType { TYPE_0, TYPE_1 } public class Sample { [JsonProperty("id")] public string Id { get; set; } = System.Guid.NewGuid().ToString(); [JsonProperty("created_at")] public Instant CreatedAt { get; set; } [JsonProperty("updated_at")] public Instant UpdateAt { get; set; } [JsonProperty("type")] public SampleType Type { get; set; } } public class Response { [JsonProperty("data")] public IEnumerable<Sample> Data { get; set; } [JsonProperty("page")] public int Page { get; set; } [JsonProperty("size")] public int Size { get; set; } [JsonProperty("count")] public int Count { get; set; } [JsonProperty("total")] public int Total { get; set; } [JsonProperty("success")] public bool Success { get; set; } [JsonProperty("message")] public string Message { get; set; } }

回答 1 投票 0

如何在c#中反序列化java持续时间?

假设我从Java获得了一个持续时间:“PT-328H-46M-43.2082074S”。 如何将其反序列化为system.text.json中的NodaTime Duration?

回答 1 投票 0

如何使用 NodaTime 和 `System.Text.Json` 反序列化没有最后 Z 的 `Instant`?

我需要使用.NET的System.Text.Json反序列化一个包含UTC日期时间的JSON字符串,但我无法使用Instant的NodaTime转换器,因为该字符串缺少最后的Z(甚至

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.