String.Format日期的格式化例子:

 1 DateTime dt = DateTime.Now;//2010年10月4日 17点05分
 2             string str = "";
 3             //str = string.Format("{0:y yy yyy yyyy}", dt); //10 10 2010 2010
 4             //str = String.Format("{0:M MM MMM MMMM}", dt); //10 10 十月 十月
 5             //str = String.Format("{0:d dd ddd dddd}", dt); //4 04 周一 星期一
 6             //str = String.Format("{0:h hh H HH}", dt);   // 5 05 17 17
 7             //str = String.Format("{0:m mm}", dt);  //8 08
 8             //str = String.Format("{0:s ss}", dt);  //3 03
 9             //str = String.Format("{0:f ff fff ffff}", dt);  //9 95 953 9530
10             //str = String.Format("{0:F FF FFF FFFF}", dt);  //9 95 953 953
11             //str = String.Format("{0:t tt}", dt);  //下 下午
12             //str = String.Format("{0:z zz zzz}", dt);  //+8 +08 +08:00
13 
14             //str = String.Format("{0:d/M/yyyy HH:mm:ss}", dt); //4-10-2010 17:16:50
15             //str = String.Format("{0:M/d/yyyy}", dt);    //10-4-2010
16             //str = String.Format("{0:MM/dd/yyyy}", dt);          //10-04-2010
17             //str = String.Format("{0:ddd, MMM d, yyyy}", dt);    //周一, 十月 4, 2010
18             //str = String.Format("{0:dddd, MMMM d, yyyy}", dt);  //星期一, 十月 4, 2010
19             //str = String.Format("{0:MM/dd/yy}", dt);            //10-04-10
20             //str = String.Format("{0:MM/dd/yyyy}", dt);          //10-04-2010
21 
22             //str = String.Format("{0:t}", dt);  //17:29
23             //str = String.Format("{0:d}", dt);  //2010-10-4
24             //str = String.Format("{0:T}", dt);  //17:29:59
25             //str = String.Format("{0:D}", dt);  //2010年10月4日
26             //str = String.Format("{0:f}", dt);  //2010年10月4日 17:30
27             //str = String.Format("{0:F}", dt);  //2010年10月4日 17:31:11
28             //str = String.Format("{0:g}", dt);  //2010-10-4 17:35
29             //str = String.Format("{0:G}", dt);  //2010-10-4 17:36:18
30             //str = String.Format("{0:m}", dt);  //10月4日
31             //str = String.Format("{0:y}", dt);  //2010年10月
32             //str = String.Format("{0:r}", dt);  //Mon, 04 Oct 2010 17:37:25 GMT
33             //str = String.Format("{0:s}", dt);  //2010-10-04T17:37:43
34             str = String.Format("{0:u}", dt);  //2010-10-04 17:38:01Z
View Code

 

posted on 2015-07-29 13:35  千里烟波226  阅读(1349)  评论(0编辑  收藏  举报