Csharp 使用DateAndTime类的DateDiff计算时间间隔

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;
namespace TimeNow
{
 DateTime get_time1 = DateTime.Now;//得到当前系统时间
            DateTime sta_ontime1 = Convert.ToDateTime(//得到规定时间
                Convert.ToDateTime("2022-2-4 00:00:00"));
           txtYear.Text = DateAndTime.DateDiff(//计算相隔年数
               "yyyy", get_time1, sta_ontime1,
               FirstDayOfWeek.Sunday, 
               FirstWeekOfYear.FirstFourDays).ToString();
}

发布日期:

所属分类: 编程, 编程语言 标签: