将日期转换为ISO日期格式C#

时间:2015-03-16 05:46:09

标签: c#

我有一个日期值,例如:

string date = "02/14/2015" //(MM/DD/YYY)

我想将其转换为ISO日期格式。无论如何都要这样做..

3 个答案:

答案 0 :(得分:0)

使用DateTime.ParseExact(dateString, format, provider);功能。

https://msdn.microsoft.com/en-us/library/w2sa9yss%28v=vs.110%29.aspx

示例:

CultureInfo provider = CultureInfo.InvariantCulture;
string date = "02/14/2015";
string format = "dd/mm/yyyy";

// Result is now a DateTime and can be easily converted
DateTime result = DateTime.ParseExact(date, format, provider);

答案 1 :(得分:0)

试试这个:

string date = "02/14/2015"

DateTime NewDate= DateTime.ParseExact(dateString, "MM/DD/YYYY", 
CultureInfo.InvariantCulture);

string NewFmt=NewDate.ToString("yyyy/MM/DD");

答案 2 :(得分:0)

试试这个...

string date = "02/14/2015";
DateTime d2 = DateTime.Parse(date, null, DateTimeStyles.RoundtripKind);