C # Calculate the time difference between the input time and today,

Source: Internet
Author: User

C # Calculate the time difference between the input time and today,

/// <Summary>
/// Calculate the time difference between the input time and the current day
/// </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 = 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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.