How to create array of TimeZone objects in VB.NET

1 Answer

0 votes
Public Class TimeZoneClass
    Private dt As DateTimeOffset
    Private tz As TimeZoneInfo

    Public Sub New(dateTime As DateTimeOffset, timeZone As TimeZoneInfo)
        dt = dateTime
        tz = timeZone
    End Sub

    Public ReadOnly Property DateTime As DateTimeOffset
        Get
            Return dt
        End Get
    End Property

    Public ReadOnly Property TimeZone As TimeZoneInfo
        Get
            Return tz
        End Get
    End Property
End Class

Module Module1

    Sub Main()

        Dim timeZoneObjects() As TimeZoneClass = {New TimeZoneClass(Date.Now, TimeZoneInfo.Local),
                                                 New TimeZoneClass(Date.Now, TimeZoneInfo.Utc)}
        For Each timeZoneO In timeZoneObjects
            Console.WriteLine("{0}: {1:G}",
                              If(timeZoneO.TimeZone Is Nothing, "<null>", timeZoneO.TimeZone),
                              timeZoneO.DateTime)
        Next

    End Sub

End Module

' run:
' 
' (UTC+02:00) Jerusalem: 12-4-16 8:00:50 AM
' UTC: 12-4-16 8:00:50 AM

 



answered Apr 12, 2016 by avibootz

Related questions

1 answer 212 views
1 answer 180 views
180 views asked Apr 12, 2016 by avibootz
1 answer 216 views
3 answers 146 views
1 answer 195 views
195 views asked Aug 5, 2022 by avibootz
1 answer 198 views
...