码迷,mamicode.com
首页 > 其他好文 > 详细

多种时间验证方法

时间:2014-08-01 13:04:41      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   os   io   数据   

方法一:Json方法 通过对查询出来的结果进行比较 使用函数CompareTo()

            //Json方法
            HttpContext.Current.Response.ContentType = "application/json";
            DateTime[] times = BLL.Order.TimeBJManager.GetDateSchoolTime();
            //times t1 = NowDT.   (dt2); //NowDT 早于 dt2,返回 -1  
            //times t2 = NowDT.CompareTo(dt1); //NowDT 晚于 dt1,返回 1
            //times t3 = NowDT.CompareTo(dt2); //NowDT  ==  dt2,返回 0
            if (NowDT.CompareTo(times[0]) < 0 || NowDT.CompareTo(times[1]) > 0)
            {
                //当前时间 早于开始时间
                //当前时间 晚于结束时间
                string json = "{\"StartTime\":\"" + times[0] + "\",\"EndTime\": \"" + times[1] + "\"}";
                HttpContext.Current.Response.Write(json);
            }
            else
            {
                HttpContext.Current.Response.Write(null);
            }

方法二:通过查询数据库,在数据库中比较时间 使用函数 CONVERT(data_type(length),data_to_be_converted,style)

        DataTable dt=new DataTable();
        /// <summary>
        /// 时间验证
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public void Timeyanzheng()
        {
            StringBuilder strHtml = new StringBuilder();
            DateTime NowDT = DateTime.Now;
            dt = new BLL.list.Lists().list("SYS_APPConfig", "Id,type,convert(varchar(100),StartDate,23) as StartDate,convert(varchar(100),EndDate,23) as EndDate", "").Tables[0];
           // DataSet ds = new BLL.list.Lists().list("SYS_APPConfig", "convert(varchar(100),StartDate,23) as StartDate,convert(varchar(100),EndDate,23) as EndDate", " type=‘学校端设置‘ and StartDate<‘" + NowDT + "‘ and EndDate>‘" + NowDT + "‘");
            DataRow[] dr = dt.Select("type=‘学校端设置‘ and StartDate<‘" + NowDT + "‘ and EndDate>‘" + NowDT + "");
            if (dr != null && dr.Length > 0)
            {
                HttpContext.Current.Response.Write("suc");
            }
            else
            {
                DataRow[] drControl = dt.Select(" type=‘学校端设置‘");
                strHtml.AppendFormat("<div><h3>学校预约时间为:{0}  ~   {1}</h3></div>", drControl[0]["StartDate"].ToString(), drControl[0]["EndDate"].ToString());
                HttpContext.Current.Response.Write(strHtml.ToString());
            }
        }

以上是我自己用到的两种方法,至于后台的C#验证就不写了。

多种时间验证方法,布布扣,bubuko.com

多种时间验证方法

标签:style   blog   http   color   使用   os   io   数据   

原文地址:http://www.cnblogs.com/likeli/p/3884550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!