.net - Getting number of seconds in a day -
i have list of datetimes have hold time midnight, , number of seconds website considered "up" on day.
i need work out percentage of "uptime", need know how many seconds in day. wondering if there in .net similar datetime.daysinmonth(year, month) seconds in day.
my google-fu seems have let me down, , can find .net constant number of seconds in day? - doesn't take account daylight savings.
i think simple
var secondsinday = (startday.adddays(1) - startday).totalseconds;
but wondering if correct (simple not exhaustive tests indicate is)?
there more efficient way of calculating number of seconds in given day?
please note - needs take account of daylight saving hours
here function asked:
public int secondsinday(datetime datetime, string timezoneid) { var dt1 = datetime.date; var dt2 = dt1.adddays(1); var zone = timezoneinfo.findsystemtimezonebyid(timezoneid); var dto1 = new datetimeoffset(dt1, zone.getutcoffset(dt1)); var dto2 = new datetimeoffset(dt2, zone.getutcoffset(dt2)); var seconds = (dto2 - dto1).totalseconds; return (int) seconds; }
as example:
int s = secondsinday(new datetime(2013, 1, 1), "central standard time"); // 86400 int s = secondsinday(new datetime(2013, 3, 10), "central standard time"); // 82800 int s = secondsinday(new datetime(2013, 11, 3), "central standard time"); // 90000
Comments
Post a Comment