-
StackOverflow 文档
-
C# Language 教程
-
日期时间方法
-
DateTime ToString ToShortDateString ToLongDateString 和 ToString 格式化
using System;
public class Program
{
public static void Main()
{
var date = new DateTime(2016,12,31);
Console.WriteLine(date.ToString()); //Outputs: 12/31/2016 12:00:00 AM
Console.WriteLine(date.ToShortDateString()); //Outputs: 12/31/2016
Console.WriteLine(date.ToLongDateString()); //Outputs: Saturday, December 31, 2016
Console.WriteLine(date.ToString("dd/MM/yyyy")); //Outputs: 31/12/2016
}
}