在c#编程语言中,我们可以通过【DateTime】结构中的【Now】静态属性,来获取当前系统日期信息,但是,如果我们想要在开发程序中显示该系统日期信息,就需要我们将该字符串转换为字符串的形式,那么,具体该如何操作呢?news.hcsw666.com本文将为大家介绍使用ToString方法显示不同格式日期信息。
关键代码:
DateTime now = DateTime.Now;
string myDate = now.ToString("yyyy-MM-dd");
string d = now.ToString("d");
string D = now.ToString("D");
string t = now.ToString("t");
string T = now.ToString("T");
string F = now.ToString("F");
string f = now.ToString("f");
Console.WriteLine("当前系统时间是:{0},\n短日期格式:{1},\n长日期格式:{2},\n短时间格式:{3},\n长时间格式:{4},\n完整日期长时间格式:{5},\n完整日期短时间格式:{6}", myDate, d, D, t, T, F, f);
Console.ReadKey();
评论