当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET TimeSpan.ToString方法代码示例

本文整理汇总了VB.NET中System.TimeSpan.ToString方法的典型用法代码示例。如果您正苦于以下问题:VB.NET TimeSpan.ToString方法的具体用法?VB.NET TimeSpan.ToString怎么用?VB.NET TimeSpan.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

' 导入命名空间
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim intervals() As TimeSpan = { New TimeSpan(38, 30, 15), 
                                      New TimeSpan(16, 14, 30) } 
      Dim cultures() As CultureInfo = { New CultureInfo("en-US"), 
                                        New CultureInfo("fr-FR") }
      Dim formats() As String = {"c", "g", "G", "hh\:mm\:ss" }
      Console.WriteLine("{0,12}      Format  {1,22}  {2,22}", 
                        "Interval", cultures(0).Name, cultures(1).Name)
      Console.WriteLine()
      For Each interval In intervals
         For Each fmt In formats
            Console.WriteLine("{0,12}  {1,10}  {2,22}  {3,22}", 
                              interval, fmt, 
                              interval.ToString(fmt, cultures(0)), 
                              interval.ToString(fmt, cultures(1)))
         Next
         Console.WriteLine()
      Next                                                                                                                                            
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:24,代码来源:TimeSpan.ToString

输出:

Interval      Format                   en-US                   fr-FR

1.14:30:15           c              1.14:30:15              1.14:30:15
1.14:30:15           g              1:14:30:15              1:14:30:15
1.14:30:15           G      1:14:30:15.0000000      1:14:30:15,0000000
1.14:30:15  hh\:mm\:ss                14:30:15                14:30:15

16:14:30           c                16:14:30                16:14:30
16:14:30           g                16:14:30                16:14:30
16:14:30           G      0:16:14:30.0000000      0:16:14:30,0000000
16:14:30  hh\:mm\:ss                16:14:30                16:14:30

示例2: Example

Module Example
   Public Sub Main()
      Dim spans() As TimeSpan = { TimeSpan.Zero, New TimeSpan(-14, 0, 0, 0, 0), 
                                  New TimeSpan(1, 2, 3), 
                                  New TimeSpan(0, 0, 0, 0, 250), 
                                  New TimeSpan(99, 23, 59, 59, 999),
                                  New TimeSpan(3, 0, 0), 
                                  New TimeSpan(0, 0, 0, 0, 25) }
      Dim fmts() As String = { "c", "g", "G", "hh\:mm\:ss", "%m' min.'" }
      For Each span As TimeSpan In spans
         For Each fmt As String In fmts
            Console.WriteLine("{0}: {1}", fmt, span.ToString(fmt))
         Next
         Console.WriteLine()         
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:TimeSpan.ToString

输出:

c: 00:00:00
g: 0:00:00
G: 0:00:00:00.0000000
hh\:mm\:ss: 00:00:00
%m' min.': 0 min.

c: -14.00:00:00
g: -14:0:00:00
G: -14:00:00:00.0000000
hh\:mm\:ss: 00:00:00
%m' min.': 0 min.

c: 01:02:03
g: 1:02:03
G: 0:01:02:03.0000000
hh\:mm\:ss: 01:02:03
%m' min.': 2 min.

c: 00:00:00.2500000
g: 0:00:00.25
G: 0:00:00:00.2500000
hh\:mm\:ss: 00:00:00
%m' min.': 0 min.

c: 99.23:59:59.9990000
g: 99:23:59:59.999
G: 99:23:59:59.9990000
hh\:mm\:ss: 23:59:59
%m' min.': 59 min.

c: 03:00:00
g: 3:00:00
G: 0:03:00:00.0000000
hh\:mm\:ss: 03:00:00
%m' min.': 0 min.

c: 00:00:00.0250000
g: 0:00:00.025
G: 0:00:00:00.0250000
hh\:mm\:ss: 00:00:00
%m' min.': 0 min.

示例3: ToString

Module ToString
   Public Sub Main()
      Dim span As TimeSpan
      
      ' Initialize a time span to zero.
      span = TimeSpan.Zero
      Console.WriteLine(span)
      
      ' Initialize a time span to 14 days.
      span = New TimeSpan(-14, 0, 0, 0, 0)
      Console.WriteLine(span)
     
      ' Initialize a time span to 1:02:03.
      span = New TimeSpan(1, 2, 3)
      Console.WriteLine(span)
      
      
      ' Initialize a time span to 250 milliseconds.
      span = New TimeSpan(0, 0, 0, 0, 250)
      Console.WriteLine(span)
      
      ' Initalize a time span to 99 days, 23 hours, 59 minutes, and 59.9999999 seconds.
      span = New TimeSpan(99, 23, 59, 59, 999)
      Console.WriteLine(span)
      
      ' Initalize a time span to 3 hours.
      span = New TimeSpan(3, 0, 0)
      Console.WriteLine(span)
      
      ' Initalize a timespan to 25 milliseconds.
      span = New TimeSpan(0, 0, 0, 0, 25)
      Console.WriteLine(span)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:34,代码来源:TimeSpan.ToString

输出:

00:00:00
-14.00:00:00
01:02:03
00:00:00.2500000
99.23:59:59.9990000
03:00:00
00:00:00.0250000


注:本文中的System.TimeSpan.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。