// NPOI导入日期格式处理
string mytime = dateStr.Trim(); // dateStr为Excel导入的日期值
IFormatProvider culture = new CultureInfo("zh-CN", true);
string[] expectedFormats = { "dd-M月-yyyy" , "d-M月-yyyy" , "yyyy-MM-dd", "MM/yyyy/dd", "yyyyMMdd", "yyyy/MM/dd", "yyyy/M/dd", "yyyy/M/d", "M/d/yyyy h/mm/ss", "M/d/yyyy h:mm:ss tt", "M/d/yyyy" };
DateTime dateTime;
if(DateTime.TryParseExact(mytime, expectedFormats, culture, DateTimeStyles.AllowInnerWhite, out dateTime))
{
mytime = dateTime.ToString("yyyy-MM-dd");
}
else
{
mytime = dateStr.Trim();
}
// 新的 mytime 即为处理后的导入日期格式化后的字符串值
标签:26,MM,dd,mytime,yyyy,导入,2022
From: https://www.cnblogs.com/caozhengze/p/16914471.html