Convert decimal representing time to hour, minutes, seconds

前端 未结 4 1045
一向
一向 2020-12-21 02:45

I have a decimal. The range of this decimal is between 0 and 23.999999. This decimal represents a time. For example, if the decimal is 0.25, then the time it represents is 1

4条回答
  •  清酒与你
    2020-12-21 03:13

    you can use the floor function to strip off the hours and leave the minuites and seconds as a fraction of an hour. Then you can use the floor function again to strip off the minuites as a fraction of an hour. you are then left with the seconds ( as fractions of an hour )

    below a simple example to print hours and mins sunrise is in fractional hours since midnight

    printf( "sunrise %ld:%ld, \n", 
                 (long)floor( sunrise ),
                     (long)(floor( sunrise * 60 ) - 60 * floor( sunrise )) );
    

提交回复
热议问题