TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET TimeZone Example

Use the TimeZone.CurrentTimeZone property and ToLocalTime and ToUniversalTime.
TimeZone. Day and night come in different phases across the planet. We have time zones so that no one needs to wake up at midnight local time.
With TimeZone.CurrentTimeZone, we can access the current time zone information on the system. This depends on the system's configuration. We can also use conversions based on the time zone.
An example. Here we get the current time zone with TimeZone.CurrentTimeZone, a shared property in VB.NET. We see the computer is located in the Pacific Standard Time zone.

StandardName: The name of the current time zone (here it is Pacific Standard Time, PST).

DaylightName: The Day light Changes time zone name—so we know more about when the time changes each year.

VB.NET program that uses TimeZone, ToUniversalTime Module Module1 Sub Main() Dim zone As TimeZone = TimeZone.CurrentTimeZone ' Get standard and day light names. Dim standard As String = zone.StandardName Dim daylight As String = zone.DaylightName Console.WriteLine("STANDARD NAME: " + standard) Console.WriteLine("DAYLIGHT NAME: " + daylight) ' Get local and universal time for DateTime.Now. Dim local As DateTime = zone.ToLocalTime(DateTime.Now) Dim universal As DateTime = zone.ToUniversalTime(DateTime.Now) Console.WriteLine("LOCAL TIME: " + local) Console.WriteLine("UNIVERSAL TIME: " + universal) End Sub End Module Output STANDARD NAME: Pacific Standard Time DAYLIGHT NAME: Pacific Daylight Time LOCAL TIME: 7/7/2018 7:11:49 AM UNIVERSAL TIME: 7/7/2018 2:11:49 PM
Notes, ToLocalTime. We call ToLocalTime to convert a DateTime into the local time zone. In this program, the local time was the same as DateTime.Now, as Now returned a local time.
Notes, ToUniversalTime. This takes a DateTime and converts it to a universal time—one that is not based on local time. A new DateTime is returned.
A summary. Day light changes, and time zones, are a complex subject. But with the TimeZone.CurrentTimeZone property in VB.NET we gain insight into how dates and times are affected.DateTime
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf