0

When I have a value represent Date and time with Accuracy in seconds exceeds milliseconds How Can I add This Value into DateTimeClass Constructors? Since the Max Value in Millisecond with range 0 through 999.

For Example this Time 17:29:35.1012663 have more Accuracy in second and I cannot add this Value in any version of Constructors related to DateTime Class!

var Date = new DateTime(2000, 02, 02, 17, 29, 35, 1012663);
Console.WriteLine(Date);

The output: System.ArgumentOutOfRangeException

Could anyone guide me How to add this value into DateTime Object?

Ammar
  • 91
  • 2
  • 13

1 Answers1

1
public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond);

in this DateTime method the expected value for int millisecondis between 0 and 999 and you get error for this.

And for nanoseconds; DateTime.Ticks resolution is 100 nanoseconds. You can set the ticks with DateTime.AddTicks.

NOTE : AddTicks (and the other Add* methods) does not alter the DateTime, but returns a new object. So you should use as below;

date = date.AddTicks(...)
Waayd
  • 365
  • 3
  • 14