c# – DateTime.ParseExact抛出System.FormatException
为什么这行代码有时会抛出System.FormatException?
DateTime d = DateTime.ParseExact("01.07.2014","dd/MM/yyyy",CultureInfo.InvariantCulture); 解决方法
因为您的字符串和格式不匹配.
从documentation;
请改用dd.MM.yyyy格式. DateTime d = DateTime.ParseExact("01.07.2014","dd.MM.yyyy",CultureInfo.InvariantCulture); 这里是 请记住, 在你的个人资料中,它说你来自阿塞拜疆.这意味着你的 实际上,在这种情况下你使用哪种文化并不重要,因为这两种文化都有.作为 这意味着您的原始代码也适用于您的CurrentCulture. DateTime d = DateTime.ParseExact("01.07.2014",CultureInfo.CurrentCulture); // or you can use null 有关更多信息,请查看; > Custom Date and Time Format Strings (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |