VB.Net/Development/Date Format

Материал из VB Эксперт
Версия от 12:45, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Assign Date value in format: #AM#

 
Imports System
Public Class MainClass
    Shared Sub Main()
        Dim dteData As Date
        dteData = #5/5/1967 6:41:00 AM#
        "Display the date and time
        System.Console.WriteLine(dteData.ToLongDateString & " " & _
            dteData.ToLongTimeString)
    End Sub
End Class


DateTime Format French

  
Imports System
Imports System.Globalization
Imports System.Threading
Module Module1
   Sub Main()
      Dim MyCulture As CultureInfo = New CultureInfo("fr-FR")
      Dim MyDate As DateTime = Now()
      Dim dtf As DateTimeFormatInfo
      Thread.CurrentThread.CurrentCulture = MyCulture
      Console.WriteLine(MyDate.ToLongDateString())
      Console.WriteLine(MyDate.ToLongTimeString())
      Console.WriteLine(MyDate.ToShortDateString())
      Console.WriteLine(MyDate.ToShortTimeString())
      dtf = MyCulture.DateTimeFormat
      dtf.DateSeparator = "\"
      dtf.TimeSeparator = "&"
      Console.WriteLine(MyDate.ToLongDateString())
      Console.WriteLine(MyDate.ToLongTimeString())
      Console.WriteLine(MyDate.ToShortDateString())
      Console.WriteLine(MyDate.ToShortTimeString())
   End Sub
End Module


Different Date in dddd and MMMM

 
Imports System
Public Class MainClass
    Shared Sub Main()
        Dim dteData As Date
        "Get the current date and time
        dteData = Now
        System.Console.WriteLine("Weekday name: " & dteData.ToString("dddd"))
        System.Console.WriteLine("Month name: " & dteData.ToString("MMMM"))
    End Sub
End Class


Is input value a Date

  
Public Class MainClass
    Public Shared Sub Main()
        System.Console.WriteLine(IsDate("your input"))
    End Sub
    Public Shared Function IsDate(ByVal DateIn As String) As Boolean
        Dim datDateTime As DateTime
        Dim blnIsDate As Boolean = True
        Try
            datDateTime = DateTime.Parse(DateIn)
        Catch e As FormatException
            blnIsDate = False
        End Try
        Return blnIsDate
    End Function
End Class


Output time in format: "h:mm:ss tt"

 
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Diagnostics
Imports System.Drawing.Printing
Imports System.ruponentModel

Public Class MainClass
    
    Shared Sub Main()
        Console.WriteLine(Now.ToString("h:mm:ss tt"))
    End Sub
    
End Class


Show Date in different format

 
Imports System
Public Class MainClass
    Shared Sub Main()
        Dim dteData As Date
        "Get the current date and time
        dteData = Now
        "Display the results
        System.Console.WriteLine(dteData)
        "Display dates
        System.Console.WriteLine(dteData.ToLongDateString)
        System.Console.WriteLine(dteData.ToShortDateString)
        "Display times
        System.Console.WriteLine(dteData.ToLongTimeString)
        System.Console.WriteLine(dteData.ToShortTimeString)
    End Sub
End Class


To Long Date, Long Time and Universal Time

 
Imports System.IO
Module Module1
    Sub Main()
        Dim Dt As DateTime = Now()
        Console.WriteLine("Long date: " & Dt.ToLongDateString)
        Console.WriteLine("Short date: " & Dt.ToShortDateString)
        Console.WriteLine("Long time: " & Dt.ToLongTimeString)
        Console.WriteLine("Short time: " & Dt.ToShortTimeString)
        Console.WriteLine("Universal time: " & Dt.ToUniversalTime)
    End Sub
End Module