Use format specifiers to control the date display : Date Format « Date Time « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net Tutorial » Date Time » Date Format 
5.2.1.Use format specifiers to control the date display
Public Class Tester
    Public Shared Sub Main
        Dim rightNow As Date = Now
        Dim result As New System.Text.StringBuilder
        result.AppendLine("""Now""...")

        ' ----- Use format specifiers to control the date display.
        result.Append("d: ").AppendLine(rightNow.ToString("d"))
        result.Append("D: ").AppendLine(rightNow.ToString("D"))
        result.Append("t: ").AppendLine(rightNow.ToString("t"))
        result.Append("T: ").AppendLine(rightNow.ToString("T"))
        result.Append("f: ").AppendLine(rightNow.ToString("f"))
        result.Append("F: ").AppendLine(rightNow.ToString("F"))
        result.Append("g: ").AppendLine(rightNow.ToString("g"))
        result.Append("G: ").AppendLine(rightNow.ToString("G"))
        result.Append("M: ").AppendLine(rightNow.ToString("M"))
        result.Append("R: ").AppendLine(rightNow.ToString("R"))
        result.Append("s: ").AppendLine(rightNow.ToString("s"))
        result.Append("u: ").AppendLine(rightNow.ToString("u"))
        result.Append("U: ").AppendLine(rightNow.ToString("U"))
        result.Append("y: ").AppendLine(rightNow.ToString("y"))


        Console.WriteLine(result.ToString)

    End Sub

End Class
Now"...
d: 11/05/2007
D: May 11, 2007
t: 9:09 PM
T: 9:09:27 PM
f: May 11, 2007 9:09 PM
F: May 11, 2007 9:09:27 PM
g: 11/05/2007 9:09 PM
G: 11/05/2007 9:09:27 PM
M: May 11
R: Fri, 11 May 2007 21:09:27 GMT
s: 2007-05-11T21:09:27
u: 2007-05-11 21:09:27Z
U: May 12, 2007 4:09:27 AM
y: May, 2007
5.2.Date Format
5.2.1.Use format specifiers to control the date display
5.2.2.Date format: dd
5.2.3.Date format: ddd
5.2.4.Date format: dddd
5.2.5.Date format: HH:mm:ss.fff z
5.2.6.Date format: yy/MM/dd g
5.2.7.Date format: s, u, Z
5.2.8.Date format: {0:dddd},
5.2.9.Date format: {0:d} ;{1:D}
5.2.10.Date format: {0:t} ;{1:T}
5.2.11.Date format: {0:f} ;{1:F}
5.2.12.Date format: {0:g} ;{1:G}
5.2.13.Date format: {0:m} ;{1:M}
5.2.14.Date format: {0:yyyy/MM/dd HH:mm:ss}
5.2.15.Date format: {0:MMMM-dd-yy HH:mm:ss}
5.2.16.Format the current date in various ways
5.2.17.Date and time and numeric values using several different cultures.
5.2.18.Custom Format Strings
5.2.19.Defines a custom format string that displays the day of the week in parentheses after the month name, day, and year.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.