- 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.Add() Method in C#
The DateTimeOffset.Add() method in C# is used to return a new DateTimeOffset object that adds a specified time interval to the value of this instance.
Syntax
Following is the syntax −
public DateTimeOffset Add (TimeSpan t);
Example
Let us now see an example to implement the DateTimeOffset.Add() method −
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 10, 9, 45, 20, new TimeSpan(-10, 0, 0)); TimeSpan ts = new TimeSpan(20, 0, 0); DateTimeOffset res = dateTimeOffset.Add(ts); Console.WriteLine("DateTimeOffset = {0}", res); } }
Output
This will produce the following output −
DateTimeOffset = 10/11/2019 5:45:20 AM -10:00
Example
Let us now see another example to implement the DateTimeOffset.Add() method −
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset = DateTimeOffset.MinValue; TimeSpan ts = new TimeSpan(20, 0, 0); DateTimeOffset res = dateTimeOffset.Add(ts); Console.WriteLine("DateTimeOffset = {0}", res); } }
Output
This will produce the following output −
DateTimeOffset = 1/1/0001 8:00:00 PM +00:00
Advertisements