.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 >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Convert datetime to different timezone

Posted By:Rajshree       Posted Date: October 28, 2010    Points: 15    Category: DateTime    URL: http://www.dotnetspark.com  

The TimeZoneInfo.ConvertTimeBySystemTimeZoneId in .NET 3.5 and 4.0, converts a time to the time in another time zone, based on a time zone identifier. Here's how to use this method using different time zone identifiers like "India Standard Time", "Pacific Standard Time" and so on:
 

static void Main(string[] args)
{
    DateTime dt = DateTime.Now;
    Console.WriteLine("Time in Different TimeZones:\n");

    Console.WriteLine("Indian Standard Time (IST): {0}",
                TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt,
                TimeZoneInfo.Local.Id, "India Standard Time"));
    Console.WriteLine("Eastern Standard Time (EST): {0}",
                TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt,
                TimeZoneInfo.Local.Id, "Eastern Standard Time"));
    Console.WriteLine("Pacific Standard Time (PST): {0}",
                TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt,
                TimeZoneInfo.Local.Id, "Pacific Standard Time"));
    Console.WriteLine("Greenwich Mean Time (GMT): {0}",
                TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt,
                TimeZoneInfo.Local.Id, "GMT Standard Time"));
    Console.ReadLine();
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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