I can’t figure out how to convert NodaTime Instant datatype to LocalDateTime or even better to System.DateTime.
I can save Instant to postgresql database and then receive it via web service. Web service returns value:
{
"date" : "2024-05-20T14:21:39Z"
}
If I use solution from this topic:
/questions/68188327/how-do-i-configure-nodatime-serialization-in-net-5-0
and add to my code this:
options.JsonSerializerOptions.Converters.Remove(NodaConverters.InstantConverter);
options.JsonSerializerOptions.Converters.Add(new NodaPatternConverter<Instant>(InstantPattern.CreateWithCurrentCulture("uuuu-MM-dd HH:mm:ss")));
options.JsonSerializerOptions.Converters.Add(NodaConverters.CreateDateTimeZoneConverter(DateTimeZoneProviders.Tzdb));
I can get result
{
"date" : "2024-05-20 14:21:39"
}
this is almost that what I want, but not at all. My time zone is +2 hours so my local time should be:
{
"date" : "2024-05-20 16:21:39"
}
Do I have to write my own jsonconverter or is there any other simpler way to achieve that?