This is currentTime(EST) "2015-09-20 04:25:49.090". I need the below calculation.
Could you please suggest me the solution for this?
Regards, Arun
Sure - you do exactly as you've described, using TimeSpan
. You can get the time of day from a DateTime
using the TimeOfDay
property, and then just subtract that from 24 hours:
// You could use TimeSpan.FromDays(1) as well
var remaining = TimeSpan.FromHours(24) - dateTime.TimeOfDay;
Now, one thing to be wary of is that this doesn't necessarily give you the amount of time left in the day - because "local" days can be different lengths depending on time zone changes (e.g. for daylight saving time). If you need to take that into account (e.g. that on November 1st at 00:30 in New York, there's 24 1/2 hours left in the day...). That's a more complicated question - especially if you also need to take account of time zones where the day doesn't always start at 00:00.
As for the second part of getting "24 hours - remaining time" - that's just "the time of day", as you've got 24 hours - (24 hours - x)
which is just x
.
See more on this question at Stackoverflow