I have a DateTime
constructed explicitly.
var myDateTime = new DateTime(2015,1,1,0,0,0);
I have a timezone obtained explicitly.
var myTimeZone = DateTimeZoneProviders.Tzdb["America/Los_Angeles"];
myDate
is known to be represented in myTimeZone
How should I use this information to generate a ZonedDateTime
or an Instant
using NodaTime?
First, convert your DateTime
to a LocalDateTime
.
LocalDateTime ldt = LocalDateTime.FromDateTime(myDateTime);
Then you can assign it to a zone:
ZonedDateTime zdt = ldt.InZoneLeniently(myTimeZone);
And map it back to an instant:
Instant instant = zdt.ToInstant();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments