如何将日期01-05-2012转换为2012年5月1日星期二在asp.net(c#) [英] how to convert the date 01-05-2012 into Tue,1 May,2012 in asp.net(c#)
本文介绍了如何将日期01-05-2012转换为2012年5月1日星期二在asp.net(c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
2012年1月5日
将其转换为.,星期二,2012年5月1日
使用c#
01-05-2012
convert this into., Tue,1 May,2012
using c#
推荐答案
假定2012年1月5日为字符串,请首先将其转换为DateTime:
Assuming 01-05-2012 is a string, first convert it to a DateTime:
DateTime dt = DateTime.ParseExact("01-05-2012", "dd-MM-yyyy", CultureInfo.InvariantCulture);
然后您可以格式化您想要的DatetIme:
Then you can format the DatetIme as you wish:
string s = dt.ToString("ddd,d MMM,yyyy");
此处有格式字符串的完整列表:格式化DateTime显示-格式字符串说明 [
There is a full list of the formatting strings here: Formatting a DateTime for display - format string description[^]
执行以下操作:
Do this:
DateTime dt = Datetime.Now;
string date = String.Format("{0:ddd, d MMM, yyyy}", dt);
//or
string s = dt.ToString("ddd, d MMM, yyyy");
您可以执行以下操作:
字符串dt = Convert.ToDateTime("2012年5月5日").ToLongDateString();
希望这对您有所帮助.
You can Do this:
string dt=Convert.ToDateTime("01 - 05 - 2012").ToLongDateString();
Hope this is helpful for you.
这篇关于如何将日期01-05-2012转换为2012年5月1日星期二在asp.net(c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文