摘要:時間格式轉換
明明 Label.Text = dt.toString("yyyy/MM/dd");
顯示出來的日期卻永遠都是 2012-02-09
此時可以
ToString("yyyy\\/MM\\/dd")
或著
DateTime.Now.ToString("yyyy/MM/dd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
轉載:http://blog.csdn.net/meizz/article/details/626932
http://blog.darkthread.net/post-2009-04-01-date-formate-slash.aspx
//---------------------------------------------
//Long date pattern: "dddd, MMMM dd, yyyy"
//Long date string: "Wednesday, May 16, 2001"
//Long time pattern: "h:mm:ss tt"
//Long time string: "3:02:15 AM"
//Short date pattern: "M/d/yyyy"
//Short date string: "5/16/2001"
//Short time pattern: "h:mm tt"
//Short time string: "3:02 AM"
//---------------------------------------------
DateTime dt = DateTime.Now;
Console.WriteLine(dt); // 2013/03/14 下午 01:43:21
Console.WriteLine(dt.ToString("yyyyMMdd")); // 20130314
Console.WriteLine(dt.ToString("yyyy/MM/dd")); // 2013/03/14
Console.WriteLine(dt.ToString("y-MM")); // 13-03
Console.WriteLine(dt.ToString("yy-MM")); // 13-03
Console.WriteLine(dt.ToString("yyyy")); // 2013
Console.WriteLine(dt.ToString("yyyy-M")); // 2013-3
Console.WriteLine(dt.ToString("yyyy-MM")); // 2013-03
Console.WriteLine(dt.ToString("yyyy-MMM")); // 2013-三月
Console.WriteLine(dt.ToString("d")); // 2013/03/14
Console.WriteLine(dt.ToString("dd")); // 14
Console.WriteLine(dt.ToString("ddd")); // 週四
Console.WriteLine(dt.ToString("yyyy/MM/dd HH:mm:ss"));
// 2013/03/14 13:43:21
Console.WriteLine(dt.ToString("yyyy/MM/dd hh:mm:ss"));
// 2013/03/14 01:43:21
Console.WriteLine(dt.ToString("T")); // 下午 13:43:21
Console.WriteLine(dt.ToString("t")); // 下午 13:43
Console.WriteLine(dt.ToString("tt")); // 下午