01/10/2018, 11:06
Bị lỗi datetime khi build
Tại sao em code dòng:
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("Mời bạn nhập vào năm sinh: ");
string s= Console.ReadLine();
DateTime birthday = DateTime.Parse(s);
Console.WriteLine("Bạn sinh ngày: " + birthday.Day);
Console.WriteLine("Bạn sinh tháng: "+birthday.Month);
Console.WriteLine("Bạn sinh năm: " + birthday.Year);
Console.ReadLine();
Lúc em nhập dữ liệu thì nó hiện bảng thồng báo : An unhandled exception of type ‘System.FormatException’ occurred in mscorlib.dll
Additional information: String was not recognized as a valid DateTime.
Mong mấy anh giúp em a. Em cảm ơn nhiều !
Bài liên quan
String bạn nhập sai cấu trúc, xem ví dụ tại đây:
docs.microsoft.com
DateTime.Parse Method (System)
Converts the string representation of a date and time to its equivalent.