且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CONVERT日期格式从mm-dd-yyyy到dd-mmm-yyyy在c#

更新时间:2023-02-26 20:26:38

这可能有助于:)

  String myString =12-30-2014; //从文本字段获取值
DateTime myDateTime = new DateTime();
myDateTime = DateTime.ParseExact(myString,MM-dd-yyyy,null);
String myString_new = myDateTime.ToString(dd-MM-yyyy); //将myString_new添加到oracle


I am trying insert asp.net form field values to oracle database table. I have a date field which is in "MM-DD-YYYY" format. I need to add that date to oracle table. So i am trying to convert that date format to "DD-MMM-YYYY" format. But i am getting the following error.

code:

var creation_date = DateTime.ParseExact(CreationDateTextBox.Text, "DD-MMM-YYYY",null);

Text box value is: 12-12-2013.(No time) i am getting error like "String was not recognized as a valid DateTime".

This might help :)

String myString = "12-30-2014"; // get value from text field
DateTime myDateTime = new DateTime();
myDateTime = DateTime.ParseExact(myString, "MM-dd-yyyy",null);
String myString_new = myDateTime.ToString("dd-MM-yyyy"); // add myString_new to oracle