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