为什么这条线不起作用?
DateTime myDate = DateTime.ParseExact("04:05:14:17:17:09", "DD:MM:YY:HH:MM:SS", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
This format is very much not what you're trying to do.
Try changing it to dd:MM:yy:HH:mm:ss
:
DateTime myDate = DateTime.ParseExact("04:05:14:17:17:09", "dd:MM:yy:HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
So, what have I changed:
MM
refers to months, mm
is for minutes ss
needs to be lowercase dd
needs to be lowercase yy
needs to be lowercase And just for the record, I left HH
uppercase because that means it's 24-hour, but lowercase would be 12 hour.
You might want to review the Custom Date and Time Format Strings MSDN page, where all these are explained. It has some good examples that might help you.
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.