将十进制表示时间转换为小时,分钟,秒 [英] Convert decimal representing time to hour, minutes, seconds
本文介绍了将十进制表示时间转换为小时,分钟,秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个变量:
- 小时
- 分钟
- Seconds
使用此小数点,如何填写小时
,
和 Seconds
值?
解决方案
那么这里是C#中的一个答案,但在大多数语言中一般都是一样的:
int hours =(int)hoursDecimal ;
decimal minutesDecimal =((hoursDecimal - hours)* 60);
int minutes =(int)minutesDecimal;
int seconds =(int)((minutesDecimal - minutes)* 60);
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 12:15 AM. If the decimal is 23.50, the time it represents is 11:30 PM.
I have three variables: - Hours - Minutes - Seconds
Using this decimal, how do I fill in the Hours
, Minutes
, and Seconds
values?
解决方案
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);
这篇关于将十进制表示时间转换为小时,分钟,秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文