Q:

C# program to define a time zone that is not found on the local computer (TimeZoneInfo.CreateCustomTimeZone() Method)

belongs to collection: C# TimeZoneInfo Class Programs

0

Syntax:

    TimeZoneInfo TimeZoneInfo.CreateCustomTimeZone(
        string id, 
        TimeSpan baseUtcOffset, 
        string displayName, 
        string standardname);

Parameter(s):

  • id: Unique id to create custom time-zone.
  • baseUtcOffset: Time offset for custom time zone.
  • displayName: Display name for custom time zone.
  • standardname: Standard name for custom time zone.

Return value:

It returns an object of a custom time zone.

Exception(s):

  • System.ArgumentException
  • System.ArgumentNullException
  • System.ArgumentOutOfRangeException
  •  

All Answers

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

Program:

The source code to define a time zone that is not found on the local computer 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()
    {
        string displayName;
        string standardZoneName;
        TimeSpan timeOffset;
        TimeZoneInfo customZone;

        timeOffset = new TimeSpan(05, 00, 00);
        standardZoneName = "Delhi Time";
        displayName = "(GMT+05:00) Delhi/New-Delhi Time";

        customZone = TimeZoneInfo.CreateCustomTimeZone(standardZoneName, timeOffset, displayName, standardZoneName);
        
        Console.WriteLine("Current time:  "+TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, customZone));
        Console.WriteLine("Standard Name: "+customZone.StandardName);
        Console.WriteLine("Display Name:  "+customZone.DisplayName);

    }
}

Output:

Current time:  2/9/2020 2:21:36 PM
Standard Name: Delhi Time
Display Name:  (GMT+05:00) Delhi/New-Delhi Time
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 determine whether two TimeZoneInfo o... >>
<< C# program to clear cached time zone data (TimeZon...