如何更改日期格式 [英] how to change format of date
本文介绍了如何更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,其日期我想要更改为我所需的格式:
string n = dateTimePicker1.Value。 ToShortDateString();
这个函数给我回复日期为07/11/2014但是我想把它变成2014-07-11
如何更改它.........
解决方案
非常简单:
string n = dateTimePicker1 .Value.ToString( yyyy-MM-dd);
string fromFormat = dd / MM / yyyy;
string toFormat = yyyy-MM- DD跨度>;
DateTime newDate = DateTime.ParseExact( 07/11/2014 ,fromFormat,CultureInfo.InvariantCulture);
string n = newDate.ToString(toFormat);
自定义日期和时间格式字符串 [ ^ ]
i have a string that have date i want to change into my required format:
string n = dateTimePicker1.Value.ToShortDateString();
this function return me a date as 07/11/2014 but i want it into 2014-07-11
how can i change it.........
解决方案
Quite easy:
string n = dateTimePicker1.Value.ToString("yyyy-MM-dd");
string fromFormat = "dd/MM/yyyy"; string toFormat = "yyyy-MM-dd"; DateTime newDate = DateTime.ParseExact("07/11/2014", fromFormat, CultureInfo.InvariantCulture); string n = newDate.ToString(toFormat);
Custom Date and Time Format Strings[^]
这篇关于如何更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文