DateTime按照一定格式转化成String

string format = "yyyyMMdd";
Console.WriteLine(DateTime.Now.ToString(format));

String按照一定格式转化成DateTime

using System.Globalization;

DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy/MM/dd";
DateTime dt = Convert.ToDateTime("2011/05/26", dtFormat);
Console.WriteLine(dt.ToShortDateString());

snowell
365 声望11 粉丝

全栈,跨平台


引用和评论

0 条评论