當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。