Formatar data
Formatando uma data em diversos formatos:
Framework 1.1
Linguagem: VB.NET
=============
#Region "Method FormatDateTime()" Public Function FormatDateTime(ByVal strDate As String, ByVal strFormat As String) As String If strDate = "" Then Exit Function If strFormat = "" Then Exit Function Dim data As New System.DateTime(Year(strDate), Month(strDate), Day(strDate), Hour(strDate), Minute(strDate), Second(strDate)) Dim strReturn As String Select Case strFormat Case "DD/MM/YYYY" strReturn = AddZero(data.Day) & "/" & AddZero(data.Month) & "/" & data.Year Case "DD-MM-YYYY" strReturn = AddZero(data.Day) & "-" & AddZero(data.Month) & "-" & data.Year Case "DD.MM.YYYY" strReturn = AddZero(data.Day) & "." & AddZero(data.Month) & "." & data.Year Case "DD/MM/YYYY HH:MM:SS" strReturn = AddZero(data.Day) & "/" & AddZero(data.Month) & "/" & data.Year Case "DD-MM-YYYY HH:MM:SS" strReturn = AddZero(data.Day) & "-" & AddZero(data.Month) & "-" & data.Year Case "DD.MM.YYYY HH:MM:SS" strReturn = AddZero(data.Day) & "." & AddZero(data.Month) & "." & data.Year Case "HH:MM:SS" strReturn = AddZero(data.Hour) & ":" & AddZero(data.Minute) & ":" & data.Second End Select Return strReturn End Function #End Region #Region "Method AddZero()" Function AddZero(ByVal str As String) As String If str = "" Then Exit Function If Len(str) = 1 Then str = "0" & str Return str End Function #End Region
=============
Para chamar a função é simples:
FormatDateTime(now(),"DD/MM/YYYY HH:MM:SS")
Forte abraço e até o próximo!