简体   繁体   中英

How Do I Convert this specific string to a Datetime in c#?

I'm really confused I've tried a lot to get it to work.

This is the date I'm trying to convert:

6/29/17, 1:15 PM

This is the code:

DateTime.ParseExact(dateString, "MM/dd/yy, HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);

Anyone knows how to approach this?

You need to use M/dd/yy, h:mm tt format instead.

  • M specifier is for single digit month numbers without leading zero.
  • h specifier is for single hour digit 12-hour format without leading zero.

DateTime.ParseExact(dateString, "M/dd/yy, h:mm tt", CultureInfo.InvariantCulture);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM