Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否转换为年月日?_C#_Date_Webforms_Converter - Fatal编程技术网

C# 是否转换为年月日?

C# 是否转换为年月日?,c#,date,webforms,converter,C#,Date,Webforms,Converter,我有两个文本框连接到jquery日期选择器。选择日期时,该日期将以格式d m yy显示在文本框中,例如2013年10月10日。我环顾四周,发现了很多关于转换为日期的信息,但不是从这种格式,有什么方法可以做到这一点吗?您是否尝试过按如下方式格式化字符串 txtBox.ToString("d M yy"); 哎呀,我是说 dateTime.ToString("d M yy"); 您是否尝试按如下方式格式化字符串 txtBox.ToString("d M yy"); 哎呀,我是说 dateTim

我有两个文本框连接到jquery日期选择器。选择日期时,该日期将以格式
d m yy
显示在文本框中,例如2013年10月10日。我环顾四周,发现了很多关于转换为日期的信息,但不是从这种格式,有什么方法可以做到这一点吗?

您是否尝试过按如下方式格式化字符串

txtBox.ToString("d M yy");
哎呀,我是说

dateTime.ToString("d M yy");

您是否尝试按如下方式格式化字符串

txtBox.ToString("d M yy");
哎呀,我是说

dateTime.ToString("d M yy");
您可能需要使用
“dd-MMM-yyyy”
格式

表示从01到31的日期,表示月份的缩写名称,表示年份,为四位数

有关更多信息,请参阅

比如,

DateTime date = new DateTime(2013, 10, 10);
Console.WriteLine(date.ToString("dd MMM yyyy", CultureInfo.InvariantCulture));
输出将是

10 Oct 2013
这里有一个。

您可能需要使用
“dd-MMM-yyyy”
格式

表示从01到31的日期,表示月份的缩写名称,表示年份,为四位数

有关更多信息,请参阅

比如,

DateTime date = new DateTime(2013, 10, 10);
Console.WriteLine(date.ToString("dd MMM yyyy", CultureInfo.InvariantCulture));
输出将是

10 Oct 2013

此处a.

如果格式如前所述为2013年10月10日,您可以通过以下方式将real
DateTime
转换为此类字符串:

string format = "dd MMM yyyy";
string result = dt.ToString(format, CultureInfo.InvariantCulture); // maybe ToLower according to your string
CultureInfo.InvariantCulture
强制英语使用不同的文化

如果需要将其从
string
解析为
DateTime
,请使用
ParseExact

DateTime dt = DateTime.ParseExact("10 oct 2013", format, CultureInfo.InvariantCulture);

如前所述,如果格式为2013年10月10日,则可通过以下方式将real
DateTime
转换为该字符串:

string format = "dd MMM yyyy";
string result = dt.ToString(format, CultureInfo.InvariantCulture); // maybe ToLower according to your string
CultureInfo.InvariantCulture
强制英语使用不同的文化

如果需要将其从
string
解析为
DateTime
,请使用
ParseExact

DateTime dt = DateTime.ParseExact("10 oct 2013", format, CultureInfo.InvariantCulture);

“2013年10月10日”看起来更像是
“d MMM yyyy”
。请检查此项以供参考。我知道它看起来像MMM,但是M实际上会显示为,例如oct
“d mmmyyyy”
是该日期的.Net格式字符串。jquery日期选择器的格式字符串在这里并不重要。“2013年10月10日”看起来更像
“d MMM yyyy”
。请检查此项以获取参考。我知道它看起来像MMM,但M实际上会显示为例如oct
“d MMM yyy”
是该日期的.Net格式字符串。jquery datepicker的格式字符串在这里并不重要。我认为这不会编译,文本框上的ToString()没有接受字符串的重载。我认为这不会编译,文本框上的ToString()没有接受字符串的重载。您好,谢谢您的回答,但是,当我尝试DateTime.ParseExact时,我收到以下错误“字符串未被识别为有效的日期时间”。@Srb1313711:与2013年10月10日的
不同,您使用了什么字符串?您好,谢谢您的回答,但是,当我尝试DateTime.ParseExact时,出现以下错误“字符串未被识别为有效的日期时间”。@Srb1313711:不适用于2013年10月10日的
10
,您使用了什么字符串?