excel字符串的日期格式 [英] Date Format from excel string

查看:101
本文介绍了excel字符串的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试阅读一个excel,它有一个日期字段。但问题是某些文件可能有dd.MM.yyyy hh:mm格式的日期,而某些文件可能有MM.dd.yyyy hh:mm格式。因此,将此转换为DateTime会引发错误。我该怎么处理呢?





Hi,

I am trying to read an excel, which has a date field. But the problem is that some files may have date in dd.MM.yyyy hh:mm format where as some may have in MM.dd.yyyy hh:mm format. So while converting this to DateTime throws error. How can i handle it???


string[] formats = new[] { "MM.dd.yyyy hh:mm", "dd.MM.yyyy hh:mm", "MM/dd/yyyy hh:mm", "dd/MM/yyyy hh:mm", };
foreach (string format in formats)
{
    try
    {
        _ChangedDate = DateTime.ParseExact(dr[ConfigurationManager.AppSettings["ChangedDate"]].ToString(), format,CultureInfo.InvariantCulture);
         break;
    }
    catch
    {
    }
}





目前我已经处理过这样的非常便宜和弯曲。所以任何人都帮我解决



Currently i have handled like this which is very cheap and crooked. so anyone help me out

推荐答案

这篇关于excel字符串的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆