我想在C#中将字符串日期格式“dd/MM/yyyy”转换为“MM/dd/yyyy”
示例
string d ="25/02/2012"; i want to convert into 02/25/2012
最佳答案
您可以使用DateTime
将其解析为DateTime.ParseExact
对象,然后再使用ToString(
“MM/dd/yyyy”)to display the
DateTime`对象。
string d ="25/02/2012";
DateTime dt = DateTime.ParseExact(d, "d/M/yyyy", CultureInfo.InvariantCulture);
// for both "1/1/2000" or "25/1/2000" formats
string newString = dt.ToString("MM/dd/yyyy");
确保在顶部包括
using System.Globalization;
。
关于asp.net - 如何在ASP.NET C#中将日期字符串 “dd/MM/yyyy”格式转换为 “MM/dd/yyyy”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14978054/