C# 计算传入的时间距离今天的时间差

2018-06-22 07:51:01来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

/// <summary>
/// 计算传入的时间距离今天的时间差
/// </summary>
/// <param name="dt"></param>
/// <param name="yy"></param>
/// <param name="mm"></param>
/// <param name="dd"></param>
public void GetCriminalYX(DateTime dt, out int yy, out int mm, out int dd)
{
DateTime now = DateTime.Now;
yy = mm = dd = 0;
if (dt.Year > 9000 || dt.Year == 1900)
{
return;
}
if (dt <= now)
{
return;
}
StringBuilder str = new StringBuilder();
int dt_Y = dt.Year;
int dt_M = dt.Month;
int dt_D = dt.Day;
int now_Y = DateTime.Now.Year;
int now_M = DateTime.Now.Month;
int now_D = DateTime.Now.Day;
yy = dt_Y - now_Y;
mm = dt_M - now_M;
dd = 0;

int dt_M_SY = 0;
if (dt_D < now_D)
{
mm -= 1;
dt_M_SY = dt_M - 1;
if (dt_M_SY == 0)
{
dt_M_SY = 12;
}
if (dt_M_SY == 2)
{
dt_M_SY = dt_Y % 4 == 0 ? 29 : 28;
}
else
{
dt_M_SY = dt_M_SY == 2 || dt_M_SY == 4 || dt_M_SY == 6 || dt_M_SY == 9 || dt_M_SY == 11 ? 30 : 31;
}
dt_D += dt_M_SY;
}
dd = dt_D - now_D;
if (mm < 0)
{
yy -= 1;
mm += 12;
}
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:IIS下Advanced Logging(高级日志)的安装以及X-Forwarded-For的配

下一篇:ASP.NET前台table通过Ajax获取绑定后台查询的json数据