The DateTime.ToLocalTime() method in C# is used to convert the value of the current DateTime object to local time.
Syntax
Following is the syntax −
public DateTime ToLocalTime ();
Example
Let us now see an example to implement the DateTime.ToLocalTime() method −
using System;
public class Demo {
public static void Main() {
DateTime d = DateTime.Now;
Console.WriteLine("Date = {0}", d);
DateTime res = d.ToLocalTime();
Console.WriteLine("Local Time = {0}", res);
}
}Output
This will produce the following output −
Date = 10/16/2019 8:28:29 AM Local Time = 10/16/2019 8:28:29 AM
Example
Let us now see another example to implement the DateTime.ToLocalTime() method −
using System;
public class Demo {
public static void Main() {
DateTime d = new DateTime(2019, 10, 11, 9, 10, 45);
Console.WriteLine("Date = {0}", d);
DateTime res = d.ToLocalTime();
Console.WriteLine("Local Time = {0}", res);
}
}Output
This will produce the following output −
Date = 10/11/2019 9:10:45 AM Local Time = 10/11/2019 9:10:45 AM