![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.AddSeconds() Method in C#
The DateTimeOffset.AddSeconds() method in C# is used to return a new DateTimeOffset object that adds a specified number of whole and fractional seconds to the value of this instance.
Syntax
Following is the syntax −
public DateTimeOffset AddSeconds (double val);
Above, Val is the number of seconds to be added. To subtract seconds, set a negative value.
Example
Let us now see an example to implement the DateTimeOffset.AddSeconds() method −
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 10, 11, 7, 10, 20, new TimeSpan(-5, 0, 0)); Console.WriteLine("DateTimeOffset (before adding seconds) = {0}", dateTimeOffset); DateTimeOffset res = dateTimeOffset.AddSeconds(30); Console.WriteLine("DateTimeOffset (after adding seconds) = {0}", res); } }
Output
This will produce the following output −
DateTimeOffset (before adding seconds) = 10/11/2019 7:10:20 AM -05:00 DateTimeOffset (after adding seconds) = 10/11/2019 7:10:50 AM -05:00
Example
Let us now see another example to implement the DateTimeOffset.AddSeconds() method −
using System; public class Demo { public static void Main() { DateTimeOffset dateTimeOffset = new DateTimeOffset(2019, 11, 11, 8, 20, 10, new TimeSpan(-5, 0, 0)); Console.WriteLine("DateTimeOffset (before subtracting seconds) = {0}", dateTimeOffset); DateTimeOffset res = dateTimeOffset.AddSeconds(-10); Console.WriteLine("DateTimeOffset (after subtracting seconds) = {0}", res); } }
Output
This will produce the following output −
DateTimeOffset (before subtracting seconds) = 11/11/2019 8:20:10 AM -05:00 DateTimeOffset (after subtracting seconds) = 11/11/2019 8:20:00 AM -05:00
Advertisements