更新时间:2023-02-03 15:39:59
嗨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);