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 286 views
1 answer 270 views
270 views asked Apr 12, 2016 by avibootz
1 answer 301 views
3 answers 275 views
1 answer 278 views
278 views asked Aug 5, 2022 by avibootz
1 answer 282 views
...