DateTime.ToLocalTime() Method in C#
Last Updated :
11 Feb, 2019
This method is used to convert the value of the current DateTime object to local time.
Syntax: public DateTime ToLocalTime ();
Return Value: This method returns an object whose Kind property is Local, and whose value is the local time equivalent to the value of the current DateTime object, or MaxValue if the converted value is too large to be represented by a DateTime object, or MinValue if the converted value is too small to be represented as a DateTime object.
Below programs illustrate the use of DateTime.ToLocalTime() Method
Example 1:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
DateTime date = new DateTime(2011, 1,
1, 4, 0, 15);
DateTime value = date.ToLocalTime();
Console.WriteLine( "local time is {0}" , value);
}
}
|
Output:
local time is 01/01/2011 04:00:15
Example 2:
using System;
using System.Globalization;
class GFG {
public static void Main()
{
DateTime date = DateTime.Now;
DateTime value = date.ToLocalTime();
Console.WriteLine( "local time is {0}" , value);
}
}
|
Output:
local time is 02/11/2019 05:13:37
Reference:
Share your thoughts in the comments
Please Login to comment...