如何在下拉列表中验证开始时间和结束时间? [英] How to validate start time and end time in dropdownlist?

查看:81
本文介绍了如何在下拉列表中验证开始时间和结束时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个下拉列表ddlStartTime和ddlEndTime。在两个下拉列表中,时间以5分钟的间隔填充,例如上午12:00,上午12:05,上午12:10到下午11点55分。

我想实现服务器端验证,以便终止时间不能低于starttime。怎么做?

I have two dropdownlist ddlStartTime and ddlEndTime. In both dropdownlists time is filled with 5 minute intervals e.g. 12:00 AM, 12:05 AM, 12:10 AM upto 11.55 PM.
I want to implement server side validation so that endtime can't be less than starttime. How to do this?

推荐答案

使用DateTime.ParseExact:

Use DateTime.ParseExact:
DateTime dtStart = DateTime.ParseExact("12:00 AM", "hh:mm tt", CultureInfo.InvariantCulture);
DateTime dtEnd = DateTime.ParseExact("10:00 PM", "hh:mm tt", CultureInfo.InvariantCulture);

用您的下拉值替换常量时间,您可以直接比较两个DateTime值。

Replace the constant times with your drop down values, and you can compare the two DateTime values directly.


这篇关于如何在下拉列表中验证开始时间和结束时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆