C# Program to Convert a Time to the Time in a Particular Time Zone (Timezoneinfo.converttime() Method)

You are currently viewing C# Program to Convert a Time to the Time in a Particular Time Zone (Timezoneinfo.converttime() Method)

C# program to convert a time to the time in a particular time zone (TimeZoneInfo.ConvertTime() Method)

using System;
using System.Globalization;
using System.Collections.ObjectModel;

class TimeZoneInfoDemo
{
    //Entry point of Program
    static public void Main()
    {
        TimeZoneInfo easternStandardTime;
        DateTime time;
        DateTime convertedTime;

        time= new DateTime(2015, 2, 1, 0, 21, 20, DateTimeKind.Utc);
        easternStandardTime = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

        convertedTime = TimeZoneInfo.ConvertTime(time, easternStandardTime);

        Console.WriteLine("Time before conversion: "+ time);
        Console.WriteLine("Time After conversion:  "+ convertedTime);
    }
}
Time before conversion: 2/1/2015 12:21:20 AM
Time After conversion:  1/31/2015 7:21:20 PM
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply