Using NodaTime, how to convert Instant to the appropriate ZonedDateTime system?

I have an event log in a database where event datetime time is stored as UTC time. In my application, where I use NodaTime, I get the value as DateTime, and then convert it to Instant:

var instant = NodaTime.Instant.FromDateTimeUtc(DateTime.SpecifyKind(eventDateTime, DateTimeKind.Utc));

Now I want to get the ZonedDateTimeappropriate Instantone using the system time zone. I know what I can use instant.InZone(systemTimeZone)to get what ZonedDateTimeI need. However, I do not know how to populate a variable with the systemTimeZonecorrect value. How can I get an object DateTimeZonecorresponding to the system time zone?

+4
source share
1 answer

IDateTimeZoneProvider.GetSystemDefault . :

var systemZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
var zonedDateTime = instant.InZone(systemZone);

DateTimeZoneProviders.Bcl, TimeZoneInfo -backed.

+5

All Articles