欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c#中获取时间的方法

程序员文章站 2022-07-15 09:06:59
...
	  textBox1.Text ="获取日期 "+ DateTime.Now.ToLongDateString().ToString();
      textBox2.Text = "获取日期 " + DateTime.Now.ToShortDateString().ToString();
      textBox3.Text = "获取日期 " + DateTime.Now.ToString("yyyy-MM-dd");
      textBox4.Text = "获取日期 " + DateTime.Now.Date.ToString();

      textBox5.Text = "获取时间 " + DateTime.Now.ToLongTimeString().ToString() ;
      textBox6.Text = "获取时间 " + DateTime.Now.ToShortTimeString().ToString();
      textBox7.Text = "获取时间 " + DateTime.Now.ToString("hh:mm:ss");
      textBox8.Text = "获取时间 " + DateTime.Now.TimeOfDay.ToString();

      
      textBox9.Text = "获取日期+时间 " + DateTime.Now.ToString();
      textBox10.Text = "获取日期+时间 " + DateTime.Now.ToLocalTime().ToString();      

     
      textBox11.Text = "获取年份 " + DateTime.Now.Year.ToString();
      textBox12.Text = "获取月份 " + DateTime.Now.Month.ToString();
      textBox13.Text = "获取星期 " + DateTime.Now.DayOfWeek.ToString();
      textBox14.Text = "获取第几天 " + DateTime.Now.DayOfYear.ToString();
      textBox15.Text = "获取小时 " + DateTime.Now.Hour.ToString();
      textBox16.Text = "获取分钟 " + DateTime.Now.Minute.ToString();
      textBox17.Text = "获取秒数 " + DateTime.Now.Second.ToString();

c#中获取时间的方法