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.