如何编写程序在c#中查找单个数字的时间跨度 [英] how to write a program to find single digit in c# for timespan

查看:62
本文介绍了如何编写程序在c#中查找单个数字的时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在时间跨度的天,小时,分钟,秒中找到单个数字,并希望在每个数字之前追加零。

i want to find single digit in timespan's days,hours,minutes,seconds and want to append zero before every single digit .

推荐答案

就这样做:



如果要显示时间跨度,请使用自定义格式说明符(阅读自定义格式说明符上的文档有帮助)。



Just do like this:

If you want to display your timespan use the a custom Format specifier (reading the docu on custom format specifiers helps).

           TimeSpan ts = new TimeSpan(1, 2, 3, 4, 5); 
            string strCustom = ts.ToString(@"dd\.hh\:mm\:ss\,fff");
// Result: 01.02:03:04,005





所以诀窍就是知道如果你(例如)写ddd,你将获得至少3位数的日子...



So the trick is to know that if you (as example) write "ddd" you will get the days with a least 3 Digits...


这是格式化问题。试试

中提到的格式字符串之一 TimeSpan.ToString上的MSDN(字符串formatString) ) [ ^ ]。
That's a formatting issue. Try one of the format strings mentioned in
MSDN on TimeSpan.ToString(string formatString)[^].


int d = (int)System.DateTime.Now.DayOfWeek;
          int HH = (int)System.DateTime.Now.Hour;
          int MM = (int)System.DateTime.Now.Minute;
          int mm = (int)System.DateTime.Now.Month;
          int ss = (int)System.DateTime.Now.Second;





参考此



Refer this


这篇关于如何编写程序在c#中查找单个数字的时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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