![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DateTimeOffset.ToLocalTime() Method in C#
The DateTimeOffset.ToLocalTime() method in C# is used to convert the current DateTimeOffset object to a DateTimeOffset object that represents the local time.
Syntax
Following is the syntax −
public DateTimeOffset ToLocalTime ();
Example
Let us now see an example to implement the DateTimeOffset.ToLocalTime() method −
using System; public class Demo { public static void Main() { DateTimeOffset local; DateTimeOffset dateTimeOffset = DateTimeOffset.Now; Console.WriteLine("DateTimeOffset = {0}", dateTimeOffset); local = dateTimeOffset.ToLocalTime(); Console.WriteLine("Local Time = "+local.ToString()); } }
Output
This will produce the following output −
DateTimeOffset = 10/16/2019 11:20:35 AM +00:00 Local Time = 10/16/2019 11:20:35 AM +00:00
Example
Let us now see another example to implement the DateTimeOffset.ToLocalTime() method −
using System; public class Demo { public static void Main() { DateTimeOffset local; DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 12, 6, 10, 20, TimeSpan.Zero); Console.WriteLine("DateTimeOffset = {0}", dateTimeOffset); local = dateTimeOffset.ToLocalTime(); Console.WriteLine("Local Time = "+local.ToString()); } }
Output
This will produce the following output −
DateTimeOffset = 10/12/2019 6:10:20 AM +00:00 Local Time = 10/12/2019 6:10:20 AM +00:00
Advertisements