Difference between revisions of "Talk:LlGetWallclock"

From Second Life Wiki
Jump to navigation Jump to search
(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; …")
 
m
 
Line 16: Line 16:


[[User:Montavious Peccable|Montavious Peccable]] 00:16, 18 May 2012 (PDT)
[[User:Montavious Peccable|Montavious Peccable]] 00:16, 18 May 2012 (PDT)
:Good catch. -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 21:25, 19 May 2012 (PDT)

Latest revision as of 20:25, 19 May 2012

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)

Good catch. -- Strife (talk|contribs) 21:25, 19 May 2012 (PDT)