I am porting some code from Java to .NET and looking for a noda-time equivalent of the getMillisOfDay()
joda-time method of the LocalTime object.
Is there an equivalent one or must I code my own?
I am porting some code from Java to .NET and looking for a noda-time equivalent of the getMillisOfDay()
joda-time method of the LocalTime object.
Is there an equivalent one or must I code my own?
Closest you can get to the number of milliseconds since midnight with out-of-the-box .Net functionality:
e.g.
TimeOfDay
returns theTimeSpan
since midnight (time of day) andTotalMilliseconds
returns (the name might have given it away) the total number of milliseconds of thatTimeSpan
.It's a
double
by the way, so you'll also get fractions of milliseconds. If you need this a lot, an extension method may be helpful:In Noda Time 1.x, use the
LocalTime.TickOfDay
property, and then just divide it byNodaConstants.TicksPerMillisecond
to get milliseconds: