VB.Net/Development/Date Time Function

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

Date Time related Function

 
Imports System.IO
Module Module1
    Sub Main()
        Dim DT As DateTime = Now()
        Console.WriteLine("Day: " & Day(DT).ToString)
        Console.WriteLine("Month: " & Month(DT))
        Console.WriteLine("Year: " & Year(DT))
        Console.WriteLine("Hour: " & Hour(DT))
        Console.WriteLine("Minute: " & Minute(DT))
        Console.WriteLine("Second: " & Second(DT))
        Console.WriteLine("Today: " & Today)
        Console.WriteLine("TimeOfDay: " & TimeOfDay().ToString())
    End Sub
End Module


Next Working Day

  
Public Class MainClass
    Public Shared Sub Main()
        Dim datNewDate As Date = AddWorkingDays(Today, 1)
        System.Console.WriteLine(datNewDate)
    End Sub
    Public Shared Function AddWorkingDays(ByVal DateIn As Date, ByVal ShiftDate As Integer) As Date
        Dim datDate As Date = DateIn.AddDays(ShiftDate)
        While Weekday(datDate) = 1 Or Weekday(datDate) = 7
            datDate = datDate.AddDays(IIf(ShiftDate < 0, -1, 1))
        End While
        Return datDate
    End Function

End Class


Years Between Dates

  
Public Class MainClass
    Public Function YearsBetweenDates(ByVal StartDate As DateTime, ByVal EndDate As DateTime) As Integer
        If Month(EndDate) < Month(StartDate) Or (Month(EndDate) = Month(StartDate) And(EndDate.Day) < (StartDate.Day)) Then
            Return Year(EndDate) - Year(StartDate) - 1
        Else
            Return Year(EndDate) - Year(StartDate)
        End If
    End Function
End Class