Q:

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

belongs to collection: C# TimeZoneInfo Class Programs

0

Syntax:

    DateTime TimeZoneInfo.ConvertTime(DateTime date-time, TimeZoneInfo destTimeZone);

Parameter(s):

  • date-time: date-time to be converted in a particular time zone.
  • destTimeZone: The time zone to convert dateTime to.

Return value:

This method returns the date and time after conversion in a particular time zone.

Exception(s):

  • System.ArgumentException
  • System.ArgumentNullException
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to convert a time to the time in a particular time zone is given below. The given program is compiled and executed successfully.

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);
    }
}

Output:

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 . . .

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# TimeZoneInfo Class Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to clear cached time zone data (TimeZon... >>
<< C# program to get the system time by Zone Id...