C# TimeZone ToLocalTime

Description

TimeZone ToLocalTime returns the local time that corresponds to a specified date and time value.

Syntax

TimeZone.ToLocalTime has the following syntax.


public virtual DateTime ToLocalTime(
  DateTime time
)

Parameters

TimeZone.ToLocalTime has the following parameters.

  • time - A Coordinated Universal Time (UTC) time.

Returns

TimeZone.ToLocalTime method returns A DateTime object whose value is the local time that corresponds to time.

Example

The following code shows how to use TimeZone.ToLocalTime().


// ww  w .j av  a  2  s  .c o m
using System;
using System.Globalization;

class TimeZoneDemo
{
    static void Main( )
    {
        TimeZone localZone = TimeZone.CurrentTimeZone;
        Console.WriteLine(localZone.ToLocalTime(DateTime.Now) );
    } 
} 

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