本文介绍了在c#asp.net中将字符串转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以字符串格式(dd / mm / yyyy)获取日期时间。我想将其转换为日期时间。所以我尝试了失败的方法。所以请帮我解决这个问题。
i am getting date time in string format(dd/mm/yyyy). I want to convert to it in to datetime. So i tried bellow methods which failed. So please help me regarding this issue.
//datetime in string format from client
string mindate = 15/06/2013 11:03:24
//now i am converting above to DateTime
DateTime MinDateTime = Conevrt.ToDateTime(mintime)//getting error Message = "String was not recognized as a valid DateTime."
// another conversion
DaTeTime MinDateTime = DateTime.ParseExact(mintime)//getting error Message = "String was not recognized as a valid DateTime."
// another conversion
DaTeTime MinDateTime = DateTime.Parse(mintime)//getting error Message = "String was not recognized as a valid DateTime."
所以请帮助我关于conevrsions。谢谢。
so please help me regarding the conevrsions. Thank You.
推荐答案
string[] dateStrings = {"2008-05-01T07:34:42-5:00",
"2008-05-01 7:34:42Z",
"Thu, 01 May 2008 07:34:42 GMT"};
foreach (string dateString in dateStrings)
{
DateTime convertedDate = DateTime.Parse(dateString);
Console.WriteLine("Converted {0} to {1} time {2}.",
dateString,
convertedDate.Kind.ToString(),
convertedDate);
}
Convert.ToDateTime(mindate).ToString("dd'.'MM'.'yyyy")
谢谢
Thanks
这篇关于在c#asp.net中将字符串转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!