C# 如何使用ToSortDateString拼写月份?
现在我有这样的东西C# 如何使用ToSortDateString拼写月份?,c#,date,formatting,C#,Date,Formatting,现在我有这样的东西 string formatted_string = DateTime.Parse(sting_date).Trim()).ToShortDateString(); 这给了我2019年7月10日 我如何才能接受该代码并返回2019年10月7日的?如果您的意思是希望使用确切的代码并返回所请求的字符串,唯一的方法是首先更改当前区域性设置 CultureInfo customCulture = new CultureInfo("en"); customCulture.DateTi
string formatted_string = DateTime.Parse(sting_date).Trim()).ToShortDateString();
这给了我2019年7月10日
我如何才能接受该代码并返回2019年10月7日的
?如果您的意思是希望使用确切的代码并返回所请求的字符串,唯一的方法是首先更改当前区域性设置
CultureInfo customCulture = new CultureInfo("en");
customCulture.DateTimeFormat.ShortDatePattern = "MMMM dd, yyyy";
CultureInfo.CurrentCulture = customCulture;
在日期时间
上调用.toSortDateString()
时,它使用当前区域性的日期时间格式
中的短日期模式
。因此,通过将当前区域性更改为自定义区域性,.toSortDateString()
调用可以使用自定义格式
但这确实是一个延伸。使用.ToString(“MMMM dd,yyyyy”)
如果您的字面意思是希望使用确切的代码并取回所请求的字符串,则唯一的方法是首先更改当前区域性设置
CultureInfo customCulture = new CultureInfo("en");
customCulture.DateTimeFormat.ShortDatePattern = "MMMM dd, yyyy";
CultureInfo.CurrentCulture = customCulture;
在日期时间
上调用.toSortDateString()
时,它使用当前区域性的日期时间格式
中的短日期模式
。因此,通过将当前区域性更改为自定义区域性,.toSortDateString()
调用可以使用自定义格式
但这确实是一个延伸。使用.ToString(“MMMM-dd,yyyyy”)
一开始就要求使用该格式要容易得多。有不同于短日期格式的日期格式。使用其中一种格式(比如LongDateFormat,它返回特定的格式)。这是否回答了您的问题?你不能。有不同于短日期格式的日期格式。使用其中一种格式(比如LongDateFormat,它返回特定的格式)。这是否回答了您的问题?