首页 > 代码库 > DateTime格式
DateTime格式
DateTime dt = DateTime.Now;
DateTime.Now.ToString();//2005-11-5 13:21:25
DateTime.Now.ToFileTime().ToString();//127756416859912816
DateTime.Now.ToFileTimeUtc().ToString();//127756704859912816
DateTime.Now.ToLocalTime().ToString();//2005-11-5 21:21:25
DateTime.Now.ToLongDateString().ToString();//2005年11月5日
DateTime.Now.ToLongTimeString().ToString();//13:21:25
DateTime.Now.ToOADate().ToString();//38661.5565508218
DateTime.Now.ToShortDateString().ToString();//2005-11-5
DateTime.Now.ToShortTimeString().ToString();//13:21
DateTime.Now.ToUniversalTime().ToString();//2005-11-5 5:21:25
//DateTime.Now == 2005-11-5 13:30:28.4412864
DateTime.Now.Year.ToString();//2005
DateTime.Now.Date.ToString();//2005-11-5 0:00:00
DateTime.Now.DayOfWeek.ToString();//Saturday
DateTime.Now.DayOfYear.ToString();//309
DateTime.Now.Hour.ToString();//13
DateTime.Now.Millisecond.ToString();//441
DateTime.Now.Minute.ToString();//30
DateTime.Now.Month.ToString();//11
DateTime.Now.Second.ToString();//28
DateTime.Now.Ticks.ToString();//632667942284412864
DateTime.Now.TimeOfDay.ToString();//13:30:28.4412864
DateTime.Now.ToString();//2005-11-5 13:47:04
DateTime.Now.AddYears(1).ToString();//2006-11-5 13:47:04
DateTime.Now.AddDays(1.1).ToString();//2005-11-6 16:11:04
DateTime.Now.AddHours(1.1).ToString();//2005-11-5 14:53:04
DateTime.Now.AddMilliseconds(1.1).ToString();//2005-11-5 13:47:04
DateTime.Now.AddMonths(1).ToString();//2005-12-5 13:47:04
DateTime.Now.AddSeconds(1.1).ToString();//2005-11-5 13:47:05
DateTime.Now.AddMinutes(1.1).ToString();//2005-11-5 13:48:10
DateTime.Now.AddTicks(1000).ToString();//2005-11-5 13:47:04
DateTime.Now.CompareTo(dt).ToString();//0
DateTime.Now.Add(?).ToString();//问号为一个时间段
DateTime.Now.Equals("2005-11-6 16:11:04").ToString();//False
DateTime.Now.Equals(dt).ToString();//True
DateTime.Now.GetHashCode().ToString();//1474088234
DateTime.Now.GetType().ToString();//System.DateTime
DateTime.Now.GetTypeCode().ToString();//DateTime
DateTime.Now.GetDateTimeFormats(‘s‘)[0].ToString();//2005-11-05T14:06:25
DateTime.Now.GetDateTimeFormats(‘t‘)[0].ToString();//14:06
DateTime.Now.GetDateTimeFormats(‘y‘)[0].ToString();//2005年11月
DateTime.Now.GetDateTimeFormats(‘D‘)[0].ToString();//2005年11月5日
DateTime.Now.GetDateTimeFormats(‘D‘)[1].ToString();//2005 11 05
DateTime.Now.GetDateTimeFormats(‘D‘)[2].ToString();//星期六 2005 11 05
DateTime.Now.GetDateTimeFormats(‘D‘)[3].ToString();//星期六 2005年11月5日
DateTime.Now.GetDateTimeFormats(‘M‘)[0].ToString();//11月5日
DateTime.Now.GetDateTimeFormats(‘f‘)[0].ToString();//2005年11月5日 14:06
DateTime.Now.GetDateTimeFormats(‘g‘)[0].ToString();//2005-11-5 14:06
DateTime.Now.GetDateTimeFormats(‘r‘)[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT
Label1.Text = string.Format("{0:d}",DateTime.Now);//2005-11-5
Label2.Text = string.Format("{0:D}",DateTime.Now);//2005年11月5日
Label3.Text = string.Format("{0:f}",DateTime.Now);//2005年11月5日 14:23
Label4.Text = string.Format("{0:F}",DateTime.Now;//2005年11月5日 14:23:23
Label5.Text = string.Format("{0:g}",DateTime.Now);//2005-11-5 14:23
Label6.Text = string.Format("{0:G}",DateTime.Now);//2005-11-5 14:23:23
Label7.Text = string.Format("{0:M}",DateTime.Now);//11月5日
Label8.Text = string.Format("{0:R}",DateTime.Now);//Sat, 05 Nov 2005 14:23:23 GMT
Label9.Text = string.Format("{0:s}",DateTime.Now);//2005-11-05T14:23:23
Label10.Text = string.Format("{0:t}",DateTime.Now);//14:23
Label11.Text = string.Format("{0:T}",DateTime.Now);//14:23:23
Label12.Text = string.Format("{0:u}",DateTime.Now);//2005-11-05 14:23:23Z
Label13.Text = string.Format("{0:U}",DateTime.Now);//2005年11月5日 6:23:23
Label14.Text = string.Format("{0:Y}",DateTime.Now);//2005年11月
Label15.Text = string.Format("{0}",DateTime.Now);//2005-11-5 14:23:23
Label16.Text = string.Format("{0:yyyyMMddHHmmssffff}",DateTime.Now);
DateTime格式