How to Convert current date time different time zone (EST/PST/CST) in ASP.NET (C#) ?

Dear All,
Sometimes your application demands to covert date time in particular time zone.
.NET provided TimeZoneInfo class which help us in converting time in particular time zone.
Steps to utilize this is as follow
1) Convert time in any time zone firstly use UTC time.
2) Use TimeZoneInfo class to convert time zone from UTL to particular time

Below are some examples to utilize this

1) Convert time zone to EST (Eastern Standard Time)
DateTime EstDateTime = DateTime.UtcNow;
EstDateTime= TimeZoneInfo.ConvertTimeFromUtc(EstDateTime, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));

2) Convert time zone to PST (Pacific Standard time)
DateTime PSTDateTime = DateTime.UtcNow;
PSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(PSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"));

3) Convert time zone to Central Standard Time
DateTime CSTDateTime = DateTime.UtcNow;
CSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(CSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time "));

4) Convert time zone to GMT Standard Time
DateTime GMTDateTime = DateTime.UtcNow;
CSTDateTime= TimeZoneInfo.ConvertTimeFromUtc(CSTDateTime, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"));

I hope this will helpful to you also.

Thanks & Best Regards,
Rajat Jaiswal

Advertisements

2 thoughts on “How to Convert current date time different time zone (EST/PST/CST) in ASP.NET (C#) ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s