Torna al Thread
Public Shared Function ItNow() As DateTime
Dim timeZone As Integer = 1 'fuso orario dell'Italia!!!!!!!!!!!!!!!!!!!!!!
Dim dnow As DateTime = Date.UtcNow().AddHours(1) 'aggiungo il fuso orario all'orario UTC!!!!!!!!!!!!!!!!!!!!!!
'==========================================================================
Dim startHlegale As DateTime = DateSerial(dnow.Year, 3, System.DateTime.DaysInMonth(dnow.Year, 3)).AddHours(1 + timeZone)
While (Weekday(startHlegale) <> vbSunday) 'determino l'ultima domenica di marzo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
startHlegale = startHlegale.AddDays(-1)
End While
Dim endHlegale As DateTime = DateSerial(dnow.Year, 10, System.DateTime.DaysInMonth(dnow.Year, 10)).AddHours(1 + timeZone)
While (Weekday(endHlegale) <> vbSunday) 'determino l'ultima domenica di ottobre!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
endHlegale = endHlegale.AddDays(-1)
End While
If System.DateTime.Compare(dnow, startHlegale) > 0 AndAlso System.DateTime.Compare(dnow, endHlegale) < 0 Then
dnow = dnow.AddHours(1) 'aggiungo l'evenutale ora legale !!!!!!!!!!!!!!!!!!!!!!!!
End If
'==========================================================================
Return dnow
End Function