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 206 views
1 answer 172 views
172 views asked Apr 12, 2016 by avibootz
1 answer 209 views
3 answers 126 views
1 answer 185 views
185 views asked Aug 5, 2022 by avibootz
1 answer 192 views
...