Temporary code segment

Source: Internet
Author: User

# Region difference days

Public static string DateDiff (DateTime DateTime1, DateTime DateTime2)
{
String dateDiff = null;
TimeSpan ts1 = new TimeSpan (DateTime1.Ticks );
TimeSpan ts2 = new TimeSpan (DateTime2.Ticks );
TimeSpan ts = ts1.Subtract (ts2). Duration ();
DateDiff = ts. Days. ToString ();
Return dateDiff;
}

# Endregion

# Region differs by 222 days

Public static string DateDiff (string DateTime1, string DateTime2)
{
String dateDiff = null;
TimeSpan ts1 = new TimeSpan (DateTime. Parse (DateTime1). Ticks );
TimeSpan ts2 = new TimeSpan (DateTime. Parse (DateTime2). Ticks );
TimeSpan ts = ts1.Subtract (ts2). Duration ();
DateDiff = ts. Days. ToString ();
Return dateDiff;
}

# Endregion

# Region date comparison

Public static bool CompareDate (string FirstDay, string NextDate)
{
DateTime One = Convert. ToDateTime (FirstDay );
DateTime Two = Convert. ToDateTime (NextDate );

Return One. CompareTo (Two)> 0? True: false;
}

# Endregion

# Compare the region date and output information

Public static void CompareDateAndOutStr (string str, string FirstDay, string NextDate)
{
If (FirstDay. Length! = 10 | NextDate. Length! = 10) OutputAndEnd (str + "stage. The date length is incorrect! ");
// HttpContext. Current. Response. Write (FirstDay + "dd" + NextDate );
If (! IsValidDate (FirstDay) |! IsValidDate (NextDate ))
{OutputAndEnd (str + "stage, Date Format incorrect! ");}
DateTime One = Convert. ToDateTime (FirstDay );
DateTime Two = Convert. ToDateTime (NextDate );

If (One. CompareTo (Two)> 0)
{
OutputAndEnd (str + "stage, the end date is earlier than the start date! ");
}
}

# Endregion


# Region verify the email format

Public static bool IsValidEmail (string strIn)
{

Return System. text. regularExpressions. regex. isMatch (strIn, @ "\ w + ([-+.] \ w +) * @ \ w + ([-.] \ w + )*\. \ w + ([-.] \ w + )*");
}

# Endregion

# Region verification Date Format

Public static bool IsValidDate (string strIn)
{

Return System. Text. RegularExpressions. Regex. IsMatch (strIn, @ "^ (19 | 20) \ d {2}-(0? \ D | 1 [012])-(0? \ D | [12] \ d | 3 [01]) $ ");
}

# Endregion

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.