临时代码段

#region 相差天数


       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 相差天数222


       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 日期相比

       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


       #region 日期相比,并输出信息

       public static void CompareDateAndOutStr(string str,string FirstDay, string NextDate)
       {
           if (FirstDay.Length != 10 || NextDate.Length != 10) OutputAndEnd(str + "阶段,日期长度不正确!");
          // HttpContext.Current.Response.Write(FirstDay+"dd"+NextDate);
           if (!IsValidDate(FirstDay) || !IsValidDate(NextDate))
           { OutputAndEnd(str + "阶段,日期格式不正确!"); }
           DateTime One = Convert.ToDateTime(FirstDay);
           DateTime Two = Convert.ToDateTime(NextDate);


           if (One.CompareTo(Two)>0)
           {
               OutputAndEnd(str + "阶段,结束日期小于开始日期!");
           }
       }

       #endregion

      
       #region 验证邮件格式

      public static bool IsValidEmail(string strIn)
       {

           return System.Text.RegularExpressions.Regex.IsMatch(strIn, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
       }


       #endregion


      #region 验证日期格式

      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

你可能感兴趣的:(代码)