Computing The Time Elements (hh, mm, ss)


There are slightly different procedures for computing the time elements (hh,mm,ss) depending on the starting argument and the type of time we are computing.  e.g. is it an actual time of day or a fraction of a day converted into equivalent time elements.

All times used here will be expressed in the universal standard 00h to 24h format.

There are three basic sources of fractions that will be converted into time elements.
  • If the starting argument is a general Julian Day number ((JD), to compute the time elements from its decimal part, Algorithm 2a applies.

  • If the starting argument is a time interval expressed as a fraction of a day (DayFrac), then Algorithm 2b applies.

  • If the starting argument is a time interval expressed in decimal (hours), then Algorithm 2c applies.



Algorithm 2a:

Given any general JD number, compute the time elements (hh,mm,ss) from its decimal part.  These time elements are will all equate to integer values with the seconds value (ss) rounded-off to the nearest second.

     uu = JD + 0.5
  hours = 24*(uu - floor(uu))
     hh = floor(hours)
minutes = 60*(hours - hh)
     mm = floor(minutes)
seconds = 60*(minutes - mm)
     ss = floor(seconds + 0.5)

RANDOM EXAMPLE 1:
Given:
JD = 2428455.736324462777

To find the time of day elements (hh,mm,ss) from the decimal part of any general JD number:
     JD = 2428455.736324462777
     uu = JD + 0.5 = 2428456.236324462777
  hours = 24*(uu - floor(uu)) = 5.67178710178

     hh = floor(hours) = 05
minutes = 60*(hours - hh) = 40.3072261065
     mm = floor(minutes) = 40
seconds = 60*(minutes - mm) = 18.434
     ss = floor(seconds + 0.5) = 18
So the time of day elements, in this case, work out to:
hh:mm:ss = 05:40:18 = 05h 40m 18s
resolved to the nearest second.


Algorithm 2b:

Given a (±DayFrac) value, compute the corresponding time elements (TimeSignVal, hh, mm, ss)

 if DayFrac < 0 then TimeSignVal = -1 else TimeSignVal = 1

  hours = TimeSignVal * 24 * DayFrac
     hh = floor(hours)
minutes = 60*(hours - hh)
     mm = floor(minutes)
seconds = 60*(minutes - mm)
     ss = floor(seconds + 0.5)
or
 TimeSignVal = (DayFrac < 0)? -1:1

  hours = TimeSignVal * 24 * DayFrac
     hh = floor(hours)
minutes = 60*(hours - hh)
     mm = floor(minutes)
seconds = 60*(minutes - mm)
     ss = floor(seconds + 0.5)

RANDOM EXAMPLE 2:
Given:
DayFrac = 0.2564080683314449

To find the time elements (TimeSignVal, hh,mm,ss) corresponding to day fraction (±DayFrac):
 TimeSignVal = (DayFrac < 0)? -1:1 = 1
       hours = TimeSignVal * 24 * DayFrac = 6.15379363995
          hh = floor(hours) = 06
     minutes = 60*(hours - hh) = 9.22761839728
          mm = floor(minutes) = 09
     seconds = 60*(minutes - mm) = 13.657
          ss = floor(seconds + 0.5) = 14
So the time elements corresponding to the fraction of a day, in this case, work out to:
hh:mm:ss = 06:09:14 = 06h 09m 14s
resolved to the nearest second.


Algorithm 2c:

Given an (±hours) value, compute the corresponding time elements (TimeSignVal, hh,mm,ss).

 if hours < 0 then TimeSignVal = -1 else TimeSignVal = 1

 uu = TimeSignVal * hours
 hh = floor(uu)
 ww = 60*(uu - hh)
 mm = floor(ww)
 ss = 60*(ww - mm)
or
 TimeSignVal = (hours < 0)? -1:1

 uu = TimeSignVal * hours
 hh = floor(uu)
 ww = 60*(uu - hh)
 mm = floor(ww)
 ss = 60*(ww - mm)

RANDOM EXAMPLE 3:
Given:
hours = 9.12520543933800

To find the time elements (hh,mm,ss) corresponding to the decimal (hours) value:
 TimeSign = (9.12520543933800 < 0)? -1:1 = 1
    hours = 9.12520543933800
       hh = floor(hours) = 09
       ww = 60*(hours - hh) = 7.51232636028
       mm = floor(ww) = 07
       ss = 60*(ww - mm) = 30.740
So the time elements, corresponding to the hours value, in this case, work out to:
hh:mm:ss = 09:07:30.740 = 09h 07m 30.740s
resolved to the nearest millisecond.


© Jay Tanner - 2017