yyyyMMdd形式转成DateTime
2014-12-31 15:56:40 访问(1361) 赞(0) 踩(0)
/// <summary>
/// yyyyMMdd形式转成DateTime
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public DateTime yyyyMMddToDateTime
(
string str
)
{
if (str == null || str.Length == 0)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "str == null || str.Length == 0"
);
}
int iLen = str.Length;
if (iLen != 8)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "str.Length != 8"
);
}
string dateStr = str.Substring(0, 4) + "-" + str.Substring(4, 2) + "-" + str.Substring(6, 2);
return DateTime.Parse(dateStr);
}
标签:
yyyyMMdd形式转成DateTime 


上一条:
下一条:
相关评论
发表评论