[英]Compare DateTime from client browser and remote server, C#
Here's the scenario 这是场景
I have a ASP.NET MVC website that has a form that allows client to enter an expiry date (using JQuery datepicker), after the client submits the form I need to check from my server if the submitted date is before the current date. 我有一个ASP.NET MVC网站,其中有一个表单,允许客户端输入到期日期 (使用JQuery datepicker),客户端提交表单后我需要检查我的服务器,如果提交的日期是在当前日期之前 。
The problem is that the form or the DateTime
object does not include any field that indicates what timezone the user is in, hence I am struggling to convert it to the same timezone the server is in, then compare. 问题是表单或
DateTime
对象不包含任何指示用户所在时区的字段,因此我很难将其转换为服务器所在的时区,然后进行比较。
What is a recommend approach to solving this? 解决这个问题的建议方法是什么?
Hide a form element that contains the offset 隐藏包含偏移量的表单元素
<input type="hidden" value="" name="timezone" id="timezone" />
And set its value on page load 并在页面加载时设置其值
$(function () {
$("#timezone").value(new Date().getTimezoneOffset());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.