Class

TimeZone


Description

Used to identify a time zone in relationship to a Date.

Properties

Name

Type

Read-Only

Shared

Abbreviation

String

Handle

Ptr

SecondsFromGMT

Integer

Methods

Name

Parameters

Returns

Shared

Constructor

gmtOffsetInSeconds As Integer

Constructor

name As String

Current

TimeZone

Property descriptions


TimeZone.Abbreviation

Abbreviation As String

The abbreviation for the time zone.

This property is read-only.

Get the abbreviation for the current time zone:

Var tz As String
tz = TimeZone.Current.Abbreviation
' tz = "America/New_York", if in US Eastern Time Zone

TimeZone.Handle

Handle As Ptr

A pointer to the object for use with declares.

This property is read-only.

Important

This property is currently only supported for Android.


TimeZone.SecondsFromGMT

SecondsFromGMT As Integer

The GMT offset in seconds.

This property is read-only.

Gets the GMT offset in seconds for the current time zone:

Var gmtOffset As Integer
gmtOffset = TimeZone.Current.SecondsFromGMT
' gmtOffset = -14400 (4 hours), if US Eastern Time Zone using daylight savings time, -18000 otherwise

Method descriptions


TimeZone.Constructor

Constructor(gmtOffsetInSeconds As Integer)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a time zone using the specified GMT offset.


TimeZone.Constructor

Constructor(name As String)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a time zone using the specified name. If the name is invalid, then an InvalidArgumentException is raised.

Refer to the List of tz database time zones on Wikipedia.

Create time zone for GMT:

Var gmt As New TimeZone("GMT")
Var ny As New TimeZone("America/New_York")
Var berlin As New TimeZone("Europe/Berlin")
Var tokyo As New TimeZone("Asia/Tokyo")

TimeZone.Current

Current As TimeZone

The current time zone.

Get the current time zone:

Var tz As String
tz = TimeZone.Current.Abbreviation
' tz = "America/New_York", if in US Eastern Time Zone

Notes

Use any valid TimeZone. A list of common time zones is available here.

Sample code

Creates a DateTime for Berlin TimeZone that matches the local TimeZone's hours and minutes:

Var d As DateTime = DateTime.Now(New TimeZone("Europe/Berlin"))

Convert a date in the local time zone to the GMT time zone:

Var date1 As DateTime = New DateTime(2021, 2, 1, 13, 0, 0, 0, TimeZone.Current)
Var gmt As New TimeZone(0) ' Get GMT time zone
Var gmtDate As New DateTime(date1.SecondsFrom1970, gmt)

Compatibility

All project types on all supported operating systems.

See also

Object parent class; DateTime class