C# TimeZoneInfo ConvertTimeFromUtc

Description

TimeZoneInfo ConvertTimeFromUtc converts a Coordinated Universal Time (UTC) to the time in a specified time zone.

Syntax

TimeZoneInfo.ConvertTimeFromUtc has the following syntax.


public static DateTime ConvertTimeFromUtc(
  DateTime dateTime,
  TimeZoneInfo destinationTimeZone
)

Parameters

TimeZoneInfo.ConvertTimeFromUtc has the following parameters.

  • dateTime - The Coordinated Universal Time (UTC).
  • destinationTimeZone - The time zone to convert dateTime to.

Returns

TimeZoneInfo.ConvertTimeFromUtc method returns The date and time in the destination time zone. Its DateTime.Kind property is DateTimeKind.Utc if destinationTimeZone is TimeZoneInfo.Utc; otherwise, its DateTime.Kind property is DateTimeKind.Unspecified.

Example

The following example converts Coordinated Universal Time (UTC) to Central Time.


//  w  w  w . j  av  a2s .c o m
using System;
public class MainClass{
  public static void Main(String[] argv){  
   DateTime timeUtc = DateTime.UtcNow;

   TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
   DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone);
   Console.WriteLine(cstTime);


  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version