.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Importance of TimeZoneInfo class

Posted By:Jean Paul       Posted Date: February 03, 2011    Points: 75    Category: .Net Framework    URL: http://www.dotnetspark.com  

Importance of TimeZoneInfo class. In this articles we will see How to get all the time zones in the current system? What is the current time zone Id?
 

Importance of TimeZoneInfo class

I would like to take your attention on the following problems. 

You are working on an ASP.NET application which is hosted in a server under USA time zone?

You need to send an email to your customers daily at Singapore time zone 10 AM.  How is that possible?

How to get all the time zones in the current system?

What is the current time zone Id?

The answers for all these questions would be the TimeZoneInfo class.

TimeZoneInfo

The  TimeZoneInfo class represents any time zone in the world.  It contains a set of static methods/properties that allows us to get the current time zone information, conversion of datetime between time zones etc.


The important properties or methods are described below:

Name

Type

Description

Local

Static Property

Gets the current TimeZoneInfo of machine

GetSystemTimeZones()

Static Method

Returns the list of world TimeZoneInfo available

ConvertTime()

Static Method

Converts time in one zone to another

Id

Instance Property

String identifier of TimeZoneInfo

DisplayName

Instance Property

Display name in localized text

GetUtcOffset()

Instance Method

Returns the difference in timezone difference with Universal Time (UTC)

 

The Test Application

The test application attached provides:

  • ·         Information on Current Time Zone
  • ·         Displays list of TimeZoneInfo available

 


 

Converting current datetime to another TimeZone

So what about converting the current time to another time zone?

Here is the answer: Use the TimeZoneInfo.ConvertTime() method.

Code Example:

TimeZoneInfo timeZone = TimeZoneInfo.GetSystemTimeZones().Where(t => t.Id == "Central Standard Time").First();


DateTime
newTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZone);

The method ConvertTime() takes the current time and new time zone as arguments.


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend