双倍时间格式 [英] double to time format

查看:87
本文介绍了双倍时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我发疯了。我最近研究时间格式。我从滑块中得到一个值为double。然后我将值转换为Time,因为我需要在文本块上以时间格式显示值:[00:00:00.00]。我的问题是,现在我的代码打印的值是这样的:
$ b $ 00 00:00:00.0000000000



This is driving me crazy. I work around time format lately. I get a value from a slider as a double. Then I convert the value into Time because I need to display the value into time format : [00:00:00.00] on a textblock. My problem is that with my code now I am printing the value like this:
00:00:00.0000000000

double sliderValue = slider.Value;  
  TimeSpan Time = TimeSpan.FromHours(sliderValue);         
  this.TimeText.Text = String.Format("0:hh\\:mm", Convert.ToString(Time));





如何删除那些额外的ms?



How can I remove those extra ms ?

推荐答案

this.TimeText.Text = Time.ToString("hh\\:mm\\:ss\\:ff");


使用TimeSpan.ToString方法格式化输出...

http://msdn.microsoft.com /en-us/library/1ecy8h51(v=vs.110).aspx [ ^ ]
Use TimeSpan.ToString method to format output...
http://msdn.microsoft.com/en-us/library/1ecy8h51(v=vs.110).aspx[^]


解决方案是:



A solution was:

var slider = sender as Slider;
double sliderValue = Math.Round(slider.Value,2);
TimeSpan Time = TimeSpan.FromHours(sliderValue);
this.TimeText.Text = String.Format("{0:hh\\:mm\\:ss}",Convert.ToString(Time));


这篇关于双倍时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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