解决方案 这是我的想法.... dim TS as String =< GetTimeSpan>。 ToString TS = TS.Substring(0,LastIndexOf(":)+ 2) " Charles Law" < BL *** @ nowhere.com>在消息中写道 news:ef ************** @ TK2MSFTNGP15.phx.gbl ... 如果我显示TimeSpan我得到类似的东西:00:05:17.6217891 什么时候我想看到的是 00:05:18 有没有简单的方法来获得此输出?试着尽我所能,我找不到它。 TIA Charles Charles, 当我需要自定义格式化TimeSpan时,我通常做的是转换 它到DateTime,然后使用自定义DateTime格式。类似于: Dim ts As TimeSpan Dim dt As DateTime = DateTime.MinValue.Add(ts) Dim s作为字符串 s = ts.ToString()''默认TimeSpan格式化 s = dt.ToString(" H:mm:ss")''custom DateTime格式化 有关自定义日期时间格式的详细信息,请参阅: http://msdn.microsoft.com/library/de...matstrings.asp 有关.NET中格式化的信息,请参阅: http://msdn.microsoft.com/library/de...ttingtypes.asp - Jay [MVP - Outlook] ..NET应用程序架构师,爱好者,&福音传教士 T.S.布拉德利 - http://www.tsbradley.net " ; Charles Law < BL *** @ nowhere.com>在消息中写道 news:ef ************** @ TK2MSFTNGP15.phx.gbl ... |如果我显示TimeSpan,我会收到类似 | |的内容00:05:17.6217891 | |当我想看到的是 | | 00:05:18 | |有没有一种简单的方法来获得这个输出?尽我所能,我找不到 |它。 | | TIA | | Charles | | Charles, 另外对于其他人来说, 我用:来表达各个部分。他们之间。 小时:分钟:秒钟 如果我很懒,那就是 dim str as string = ts.ToString.length(8) (文档不太好) 我希望这有帮助, Cor If I display a TimeSpan I get something like00:05:17.6217891when what I would like to see is00:05:18Is there an easy way to get this output? Try as I might I just can''t findit.TIACharles 解决方案 Here''s my thought....dim TS as String = <GetTimeSpan>.ToStringTS=TS.Substring(0,LastIndexOf(":")+2)"Charles Law" <bl***@nowhere.com> wrote in messagenews:ef**************@TK2MSFTNGP15.phx.gbl... If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can''t find it. TIA CharlesCharles,What I normally do when I need custom formatting of a TimeSpan is "convert"it to a DateTime, then use custom DateTime formatting. Something like:Dim ts As TimeSpanDim dt As DateTime = DateTime.MinValue.Add(ts)Dim s As Strings = ts.ToString() '' default TimeSpan formattings = dt.ToString("H:mm:ss") '' custom DateTime formattingFor details on custom datetime formats see: http://msdn.microsoft.com/library/de...matstrings.aspFor information on formatting in .NET in general see: http://msdn.microsoft.com/library/de...ttingtypes.asp--Jay [MVP - Outlook]..NET Application Architect, Enthusiast, & EvangelistT.S. Bradley - http://www.tsbradley.net"Charles Law" <bl***@nowhere.com> wrote in messagenews:ef**************@TK2MSFTNGP15.phx.gbl...| If I display a TimeSpan I get something like|| 00:05:17.6217891|| when what I would like to see is|| 00:05:18|| Is there an easy way to get this output? Try as I might I just can''t find| it.|| TIA|| Charles||Charles,In addition to the others,I concatinate the individual parts with the ":" between them.Hours:Minutes:SecondsIf I am lazy it isdim str as string = ts.ToString.length(8)(not so nice as documentation)I hope this helps,Cor 这篇关于如何在没有秒的小数部分的情况下格式化TimeSpan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 06:33