I have an instrument that stores timestamps the microsecond level, and I need to store those timestamps as part of collecting information from the instrument. Note that I do
If I really needed more accuracy than the 100 ns resolution provided by DateTime
, I would consider creating a structure that contains a DateTime
and an integer value:
public struct HiResDateTime
{
public HiResDateTime(DateTime dateTime, int nanoseconds)
{
if (nanoSeconds < 0 || nanoSeconds > 99)
throw new ArgumentOutOfRangeException(...);
DateTime = dateTime;
Nanoseconds = nanoseconds;
}
... possibly other constructors including one that takes a timestamp parameter
... in the format provided by the instruments.
public DateTime DateTime { get; private set; }
public int Nanoseconds { get; private set; }
... implementation ...
}
Then implement whatever is needed, for example:
DateTime
first, then Nanoseconds
)ToString()
e.g. format DateTime to 100 ns accuracy then append nanoseconds.DateTime
HiResTimeSpan
)
... etc. ...