![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.AddTicks() Method in C#
The DateTimeOffset.AddTicks() method in C# is used to add a specified number of ticks to the value of this instance.
Syntax
Following is the syntax −
public DateTimeOffset AddTicks (long val);
Above, the Val is the ticks, which is a number of 100-nanosecond ticks. To subtract ticks, set a negative value.
Let us see the number of ticks value −
Time interval | Number of ticks |
---|---|
Second | 10,000,000 |
Minute | 600,000,000 |
Hour | 36,000,000,000 |
Day | 864,000,000,000 |
Week | 6,048,000,000,000 |
Month | It depends on the number of days in the month. |
Non-leap year | 315,360,000,000,000 |
Leap year | 316,224,000,000,000 |
Example
Let us now see an example to implement the DateTimeOffset.AddTicks() 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 adding ticks) = {0}", dateTimeOffset); // 3 seconds = 30,000,000 ticks DateTimeOffset res = dateTimeOffset.AddTicks(30000000); Console.WriteLine("DateTimeOffset (after adding ticks) = {0}", res); } }
Output
This will produce the following output −
DateTimeOffset (before adding ticks) = 11/11/2019 8:20:10 AM -05:00 DateTimeOffset (after adding ticks) = 11/11/2019 8:20:13 AM -05:00
Example
Let us now see another example to implement the DateTimeOffset.AddTicks() 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 ticks) = {0}", dateTimeOffset); // 2 seconds = 20,000,000 ticks DateTimeOffset res = dateTimeOffset.AddTicks(-20000000); Console.WriteLine("DateTimeOffset (after subtracting ticks) = {0}", res); } }
Output
This will produce the following output −
DateTimeOffset (before subtracting ticks) = 11/11/2019 8:20:10 AM -05:00 DateTimeOffset (after subtracting ticks) = 11/11/2019 8:20:08 AM -05:00
Advertisements