Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet the local and invariate date and time formats in VB .NET
DescriptionThis example shows how to get the local and invariate date and time formats in VB .NET.
Keywordsdate, time, format, invariate, local, VB.NET
CategoriesWindows, VB.NET, Software Engineering
 
The CultureInfo.CurrentCulture.DateTimeFormat() object gives information about system date and time formats. Its FullDateTimePattern, ShortDatePattern, and ShortTimePattern properties give patterns you can use in ToString to generate formatted dates and times. The InvariantInfo().FullDateTimePattern value gives a pattern for generating an invariate date and time.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Dim date_info As DateTimeFormatInfo = _
        CultureInfo.CurrentCulture.DateTimeFormat()
    lblFullDateTime.Text = date_info.FullDateTimePattern
    lblShortDate.Text = date_info.ShortDatePattern
    lblShortTime.Text = date_info.ShortTimePattern
    lblInvariant.Text = _
        date_info.InvariantInfo().FullDateTimePattern
    lblExFullDateTime.Text = _
        Now.ToString(date_info.FullDateTimePattern)
    lblExShortDate.Text = _
        Now.ToString(date_info.ShortDatePattern)
    lblExShortTime.Text = _
        Now.ToString(date_info.ShortTimePattern)
    lblExInvariant.Text = _
        Now.ToString(date_info.InvariantInfo().FullDateTimePattern)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated