将字符串转换为有效日期时间 [英] convert string to valid datetime
本文介绍了将字符串转换为有效日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将此字符串1-Jan-2014 at 16:18转换为有效日期时间
how to convert this string " 1-Jan-2014 at 16:18 " to valid date time
推荐答案
嗨Sadhana,
请参阅以下链接,了解字符串到日期时间的转换。希望这对你有帮助。
Easy String to DateTime,DateTime to String and Formatting [ ^ ]
http://msdn.microsoft.com/en-IN/library/cc165448.aspx [ ^ ]
Hi Sadhana,
Please see the below links for string to datetime conversion. Hope this will help you.
Easy String to DateTime, DateTime to String and Formatting[^]
http://msdn.microsoft.com/en-IN/library/cc165448.aspx[^]
让我先回答你的评论。对于这样的修改代码:
Let me answer your comment first. For that modify code like this:
BASICDATETIMEOFINVOICE = "1-Jan-2014";
DateTime date = DateTime.ParseExact(BASICDATETIMEOFINVOICE, "d-MMM-yyyy", CultureInfo.InvariantCulture);
对于你的问题,代码应该是这样的:
And for your question,code should go like this:
DateTime date =DateTime.ParseExact("1-Jan-2014 16:18","d-MMM-yyyy HH:mm",CultureInfo.InvariantCulture);
重要提及: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v = vs.110).aspx [ ^ ]
问候..
Important to refer : http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]
Regards..
使用此代码
Use this code
string myDate = "02-Mar-2014";
DateTime myDateTime;
myDateTime = Convert.ToDateTime(myDate);
string newDate = myDateTime.ToString("mm/yyyy/dd");
MessageBox.Show(newDate);
这篇关于将字符串转换为有效日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文