如何转换日期字符串"dd/MM/yyyy"格式化为"MM/dd/yyyy"在asp.net C#? [英] How to convert a date string "dd/MM/yyyy" format into "MM/dd/yyyy" in asp.net c#?
本文介绍了如何转换日期字符串"dd/MM/yyyy"格式化为"MM/dd/yyyy"在asp.net C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在C#中将字符串日期格式"dd/MM/yyyy"转换为"MM/dd/yyyy"例子
I want to convert a string date formate "dd/MM/yyyy" into "MM/dd/yyyy" in c# example
string d ="25/02/2012"; i want to convert into 02/25/2012
推荐答案
您可以使用 DateTime.ParseExact
将其解析为 DateTime
对象,然后再使用 ToString(
"MM/dd/yyyy")以显示
DateTime`对象.
You can parse it to DateTime
object using DateTime.ParseExact
and later use ToString(
"MM/dd/yyyy")to display the
DateTime` object like.
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");
确保在顶部使用System.Globalization; 包含.
Make sure to include using System.Globalization;
at the top.
这篇关于如何转换日期字符串"dd/MM/yyyy"格式化为"MM/dd/yyyy"在asp.net C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文