Convert decimal representing time to hour, minutes, seconds

前端 未结 4 1058
一向
一向 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 02:54

    Well, here's an answer in C#, but it's generally the same idea in most languages:

    int hours = (int)hoursDecimal;
    decimal minutesDecimal = ((hoursDecimal - hours) * 60);
    int minutes = (int)minutesDecimal;
    int seconds = (int)((minutesDecimal - minutes) * 60);
    

提交回复
热议问题