首页 > 代码库 > String.Format,DateTime日期时间格式化集锦

String.Format,DateTime日期时间格式化集锦

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