天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Common.TextUtil
{
public static class DateTimeUtil
{
/// <summary>
/// 计算两个时间的间隔
/// </summary>
/// <param name="dt1">第一个时间</param>
/// <param name="dt2">第二个时间</param>
/// <returns></returns>
public static TimeSpan DateDiff(DateTime dt1, DateTime dt2)
{
TimeSpan ts1 = new TimeSpan(dt1.Ticks);
TimeSpan ts2 = new TimeSpan(dt2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
return ts;
}
/// <summary>
/// 计算一个时间与当前本地时间的间隔
/// </summary>
/// <param name="dt">一个时间</param>
/// <returns></returns>
public static TimeSpan DateDiff(DateTime dt)
{
return DateDiff(dt, DateTime.Now);
}
/// <summary>
/// yyyy-MM-dd HH:mm:ss
/// </summary>
public const string DATETIME_YYYYMMDD_HHMMSS = "yyyy-MM-dd HH:mm:ss";
}
}