Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

c# - How to parse datetime with DateTime.ParseExact

I have the following string that I need to parse

string date = "2017-06-23T13:45:45.816"

What is correct format string?

I tried

DateTime createDate = DateTime.ParseExact(date, "yyyy-MM-dd'T'hh-mm-ss", CultureInfo.InvariantCulture);
question from:https://stackoverflow.com/questions/65873397/is-there-a-way-to-convert-string-15-jan-21-to-a-valid-datetime

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

yyyy-MM-dd'T'hh-mm-ss is not 2017-06-23T13:45:45.816 you have missing milliseconds, 12 hour clock and also wrong separators.

You'd probably need something like:

"yyyy-MM-dd'T'HH:mm:ss.fff"

Remember it's ParseExact.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...