将时间值转换为正常时间 [英] Convert time value to normal time

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

问题描述


我有以下示例值:
< 24:05,25:08,26:59>
我需要一个函数或其他东西来获取正确的时间值(hh:mm),例如:
< 00:05,01:08,02:59>
C#中是否存在执行此操作的方法?

请帮帮我,我会为此而疯狂的!!

谢谢!
干杯..
Alessandro

Hi,
I have the following example values:
<24:05 , 25:08 , 26:59>
and I need a function or something else to get a correct time value (hh:mm) like:
<00:05 , 01:08 , 02:59>
Does exists a method in C# to do that?

Please help me, I gonna to be crazy on this!!

Thx!
Cheers..
Alessandro

推荐答案

您所说的正常时间"根本不是时间!这只是时间的字符串表示.时间本身由System.DataTime表示,没有任何特定格式.时间就是时间,没有24小时或12小时时间,日历本身与文化无关.

顺便说一句,您在示例中显示的12小时格式显示的时间是不确定的,因为它也需要AM/PM说明符.另外,称其为正常"也是荒谬的.在许多文化中,人们会觉得它很不正常.不要试图声称自己的习惯具有普遍价值. :-)

因此,要解决您的问题,请查看方法System.DataTime.ToString和各种格式说明符.此方法名称已重载,因此有几种方法.您可以将其与format provider的参数一起使用,并将类System.Globalization.CultureInfo的实例用作IFormatProvider.您始终可以使用低级格式字符串.

请在此处查看带有格式提供程序的代码示例: http://msdn.microsoft.com/en-us/library /ht77y576.aspx [ ^ ].
请参阅这些类的帮助:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ], http://msdn.microsoft.com/en-us/library/system.globalization. cultureinfo.aspx [ ^ ].

—SA
What you call "normal time" is not time at all! This is just a string presentation of time. The time itself is represented by System.DataTime and does not have any certain format. Time is time, there is not 24-hour time or 12-hour time, and the calendar itself is culture-independent.

By the way, your 12-hour format you show in your example shows indefinite time, because it also needs AM/PM specifiers. Also, calling it "normal" is ridiculous. In many cultures people will perceive it like quite abnormal. Don''t try to claim your habits have universal value. :-)

So, to solve your problem look at the method System.DataTime.ToString and various format specifiers for time. This method name is overloaded, so there are several method. You could use the one with the parameter of format provider and use the instance of the class System.Globalization.CultureInfo as IFormatProvider. You can always use low-level format string.

See the code sample with format provider here: http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^].
See the help on these classes:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^], http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx[^].

—SA


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

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