转载:https://www.cnblogs.com/webfans/p/3627868.html
Console.WriteLine("ToShortDateString:" + DateTime.Now.ToShortDateString()); Console.WriteLine("ToLongDateString:" + DateTime.Now.ToLongDateString()); Console.WriteLine("ToShortTimeString:" + DateTime.Now.ToShortTimeString()); Console.WriteLine("ToLongTimeString:" + DateTime.Now.ToLongTimeString()); Console.WriteLine(DateTime.Now.ToString()); Console.WriteLine(DateTime.Now.ToString("t")); Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")); Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ms")); Console.WriteLine(DateTime.Now.ToString("d")); //格式: 2010-10-22 Console.WriteLine(DateTime.Now.ToString("D")); //格式: 2010年10月22日 Console.WriteLine(DateTime.Now.ToString("f")); //格式: 2010年10月22日 9:26 Console.WriteLine(DateTime.Now.ToString("F")); //格式: 2010年10月22日 9:26:38 Console.WriteLine(DateTime.Now.ToString("g")); //格式: 2010-10-22 9:26 Console.WriteLine(DateTime.Now.ToString("G")); //格式: 2010-10-22 9:26:38 Console.WriteLine(DateTime.Now.ToString("m")); //格式: 10月22日 Console.WriteLine(DateTime.Now.ToString("r")); //格式: Fri, 22 Oct 2010 09:26:38 GMT Console.WriteLine(DateTime.Now.ToString("s")); //格式: 2010-10-22T09:26:38 Console.WriteLine(DateTime.Now.ToString("t")); //格式: 9:26 Console.WriteLine(DateTime.Now.ToString("T")); //格式: 9:26:38 Console.WriteLine(DateTime.Now.ToString("u")); //格式: 2010-10-22 09:26:38Z Console.WriteLine(DateTime.Now.ToString("U")); //格式: 2010年10月22日 1:26:38 Console.WriteLine(DateTime.Now.ToString("y")); //格式: 2010年10月 Console.WriteLine(DateTime.Now.ToString("dddd")); //格式: 星期五 Console.WriteLine(DateTime.Now.ToString("dddd, MMMM dd yyyy")); //格式: 星期五, 十月 22 2010 Console.WriteLine(DateTime.Now.ToString("ddd, MMM d yy")); //格式: 五, 十月 22 10 Console.WriteLine(DateTime.Now.ToString("dddd, MMMM dd")); //格式: 星期五, 十月 22 Console.WriteLine(DateTime.Now.ToString("M/yy")); //格式: 10-10 Console.WriteLine(DateTime.Now.ToString("dd-MM-yy")); //格式: 22-10-10