使用指定格式的字符串变量格式化日期字符串,DateAndTime取时间间隔

 private void btn_GetTime_Click(object sender, EventArgs e)

        {

            lab_time.Text =

                DateTime.Now.ToString("d") + "\n" +//使用指定格式的字符串变量格式化日期字符串

                DateTime.Now.ToString("D") + "\n" +

                DateTime.Now.ToString("f") + "\n" +

                DateTime.Now.ToString("F") + "\n" +

                DateTime.Now.ToString("g") + "\n" +

                DateTime.Now.ToString("G") + "\n" +

                DateTime.Now.ToString("R") + "\n" +

                DateTime.Now.ToString("y") + "\n" +

                "当前系统时间为:"+DateTime.Now.ToString(//使用自定义格式格式化字符串

                "yyyy年MM月dd日 HH时mm分ss秒");

        }

效果图

 

 private void btn_Get_Click(object sender, EventArgs e)

        {

            MessageBox.Show("间隔 "+

                DateAndTime.DateDiff(//使用DateDiff方法获取日期间隔

                DateInterval.Day, dtpicker_first.Value, dtpicker_second.Value,

                FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1).ToString()+"", "间隔时间");



        }

  

你可能感兴趣的:(Date)