Example sharing of how C# calculates the time difference between the incoming time and today

黄舟
Release: 2017-08-09 10:47:28
Original
1731 people have browsed it

C#Example sharing of how to calculate the time difference between the incoming time and today

///  /// 计算传入的时间距离今天的时间差 ///  ///  ///  ///  ///  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; } }
Copy after login

The above is the detailed content of Example sharing of how C# calculates the time difference between the incoming time and today. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!