我有Excel文件,我在这里以字符串格式获取日期为“30-12-1899 07:50:00:AM”
当我尝试将其转换为DATETIME
时,它会给出错误
String was not recognized as a valid DateTime
我正在尝试将其转换为
Convert.ToDateTime(homeToSchool[7],new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "-" })
答案 0 :(得分:3)
string myDate = "30-12-1899 07:50:00:AM";
DateTime dt1 = DateTime.ParseExact(myDate, "dd-MM-yyyy hh:mm:ss:tt",
CultureInfo.InvariantCulture)
有关日期和时间格式字符串的更多信息,
答案 1 :(得分:0)
既然你是从excel阅读这篇文章的,我希望这会有所帮助
DateTime.FromOADate(homeToSchool[7].ToString("dd-MMM-yyyy");