yyyyMMddHHmmss形式转成DateTime
2014-12-31 15:59:39 访问(1436) 赞(0) 踩(0)
/// <summary>
/// yyyyMMddHHmmss形式转成DateTime
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public DateTime DateTimeConvertby_yyyyMMddHHmmss
(
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 != 14)
{
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)
+ " " + str.Substring(8, 2)
+ ":" + str.Substring(10, 2)
+ ":" + str.Substring(12, 2);
return DateTime.Parse(dateStr);
}
标签:
yyyyMMddHHmmss形式转成DateTime 


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