如何将时间跨度转换为十进制 [英] How do I convert timespan into decimal

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

问题描述

在Windows应用程序中我需要将HH:MM时间跨度转换为十进制HH.MM ..请紧急帮助我



我是什么尝试过:



TimeSpan StartTime = TimeSpan.Parse(dtpStartTime.Value.ToString(HH:MM));

TimeSpan EndTime = TimeSpan.Parse(dtpEndTime.Value.ToString(HH:MM));



if(StartTime< = EndTime)

{

WorkingHours =(EndTime - StartTime);

加倍;



int j = Convert.ToInt32(TotalDays.ToString());

for(int i = 1; i< = j; i ++)

{



TotalHour = + WorkingHours;

th = Convert.ToDecimal((TotalHour).ToString(#。00));



}

In windows application I need to convert a HH:MM timespan into decimal HH.MM.. Please help me with the same urgently

What I have tried:

TimeSpan StartTime = TimeSpan.Parse(dtpStartTime.Value.ToString("HH:MM"));
TimeSpan EndTime = TimeSpan.Parse(dtpEndTime.Value.ToString("HH:MM"));

if (StartTime <= EndTime)
{
WorkingHours = (EndTime - StartTime);
double th;

int j= Convert.ToInt32(TotalDays.ToString());
for (int i = 1; i <= j; i++)
{

TotalHour =+ WorkingHours;
th=Convert.ToDecimal((TotalHour).ToString(#.00));

}

推荐答案

这取决于您希望如何重复最终值。请参阅 TimeSpan Structure(System) [ ^ ]。使用 TotalXxx()属性将总值设置为使用分数或其他属性的两倍,以将天/小时/分钟/秒部分作为整数。



不使用字符串。使用数值进行计算,最后将其转换为输出字符串。
It depends on how you want the final value to be repesented. See the TimeSpan Structure (System)[^]. Use the TotalXxx() properties to get the total value as double with fractions or the other properties to get the days / hours / minutes / seconds parts as integers.

Don't work with strings. Use the numeric values for calculation and convert finally to string for output.


这篇关于如何将时间跨度转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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