I'm not completely sure what you are asking, but here are some tips:
If all you need is "now" as a UTC
DateTime
, just useDateTime.UtcNow
.If you are working with Noda Time instants and need a
DateTime
, just useinstant.ToDateTimeUtc()
. There's no point in working with time zones if you just need UTC.If you want to validate a
DateTime
is in UTC, then check the kind:dateTime.Kind == DateTimeKind.Utc
Your data layer will probably return
DateTimeKind.Unspecified
kinds ofDateTime
, so you would need to first specify the UTC kind before converting to a Noda TimeInstant
:DateTime dt = (DateTime) dataReader["YourDataField"]; DateTime utc = DateTime.SpecifyKind(dt, DateTimeKind.Utc); Instant instant = Instant.FromDateTimeUtc(utc);
Lastly, recognize that UTC isn't a format. It's a time scale. So a value can be "adjusted to UTC", or "of UTC kind", but it can't be "in UTC format".