Talk:LlGetWallclock

From Second Life Wiki
Revision as of 23:16, 17 May 2012 by Montavious Peccable (talk | contribs) (Created page with "I simplified the example code to calculate hours, minutes and seconds. The old code was: integer seconds = now % 60; integer minutes = ((now - seconds) % 3600) / 60; …")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I simplified the example code to calculate hours, minutes and seconds. The old code was:

   integer seconds = now % 60;
   integer minutes = ((now - seconds) % 3600) / 60;
   integer hours = (now - minutes - seconds) / 3600;

If it were necessary to subtract the odd minutes and seconds before dividing, then the hour calculation above would be incorrect - the formula for hours would have to be

   integer hours = (now - 60 * minutes - seconds) / 3600;

However, since integer division truncates the fractional part of the quotient, there's no need to subtract anything. This code will work just as well:

   integer seconds = now % 60;
   integer minutes = (now / 60) % 60;
   integer hours = now / 3600;

Montavious Peccable 00:16, 18 May 2012 (PDT)