.NET datetime Millisecond precision issue when converting from string to date and time

Hello. I am trying to convert an incoming datetime value that comes to our system in a string format. It seems that when the precision of milliseconds is above 7, the datetime parsing in .NET is not like a value and cannot convert / parse a value. I am a little fixated on what to do for this? My only thought is that there is a millisecond limit, and that more accuracy is impossible? But I want to confirm that this is so, and not to assume. Example:

string candidateDateTimeString = "2017-12-08T15:14:38.123456789Z";
if (!success)
        {
            success = DateTime.TryParseExact(trayportDateTimeString, "yyyy-
MM-dd'T'HH:mm:ss.fffffffff'Z'",
                CultureInfo.InvariantCulture, dateTimeStyles, out dateTime);
        }

If I reduce the value of "f" to 7, then the date syntax will work fine. Is there a limit? Or am I doing something obvious wrong?

+4
source share
3

docs, 7 - .

+3

, . :

DateTime

DateTime 01.01.0001 00:00 64- . - 100 . , , . , , . , 100 , , Int64 .

DateTime.Now

DateTime.Now, , DateTime . , .

Stopwatch

Stopwatch, , , , DateTime.Now, 100 . .

, , (, ), DateTime . , .

0

Source: https://habr.com/ru/post/1690477/


All Articles