解析當我嘗試這個字符串解析成日期:字符串的不正確的格式時DateTime.ParseExact
1.05.2016
有了這個代碼:
var startDate = DateTime.ParseExact(Console.ReadLine(),
"dd.m.yyyy", CultureInfo.InvariantCulture);
出現錯誤:
Unhandled Exception: System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
at _09.Holidays_Between_Two_Dates.Program.Main(String[] args) in C:\Users\martin\documents\visual studio 2015\Projects\Methods. Debugging - Troubleshooting Code\09. Holidays Between Two Dates\09. Holidays Between Two Dates.cs:line 15
有人可以幫忙嗎?提前致謝。
嘗試'「d.MM.yyyy」'作爲格式 – Pikoh
[?我如何以不同的格式格式化日期時間(http://stackoverflow.com/questions/35650681/how-do-i-format-a-datetime-in-a-different-format) – CodeCaster