C#中String类型和DateTime类型之间的互相转换。
文章目录
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());
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论