字符串不是有效的日期时间 - 文化信息 [英] string is not valid datetime - culture info

查看:139
本文介绍了字符串不是有效的日期时间 - 文化信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

Dear All,

if (IsPostBack)
{
 AttendanceDate = DateTime.Parse(HttpContext.Current.Session["AttendanceLogDate"].ToString()); 
}
else
{
 AttendanceDate = Convert.ToDateTime(HttpContext.Current.Session["AttendanceLogDate"].ToString());
}



以上代码运行正常。请澄清为什么这种转换需要回发。



现在,我已经改变了我的工作机器VS2012。现在上面的代码不起作用并抛出string is not valid datetime。


The above code is working fine. Please clarify me that why this conversion requires postbacks.

Now, I have changed my working machine,VS2012. Now the above code is not working and throws "string is not valid datetime".

推荐答案

使用下面的代码:



use below code :

DateTime tempDate;
if (HttpContext.Current.Session["AttendanceLogDate"] != null && DateTime.TryParse(HttpContext.Current.Session["AttendanceLogDate"].ToString(), out tempDate))
{
  AttendanceDate = tempDate;
}


这篇关于字符串不是有效的日期时间 - 文化信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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