将十进制表示时间转换为小时,分钟,秒 [英] Convert decimal representing time to hour, minutes, seconds

查看:288
本文介绍了将十进制表示时间转换为小时,分钟,秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小数点。此小数的范围介于0和23.999999之间。这个十进制代表一个时间。例如,如果小数是0.25,那么它代表的时间是12:15 AM。如果小数位数为23.50,则表示的时间为11:30 PM。



我有三个变量:
- 小时
- 分钟
- 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆