如何获得服务器端日期 [英] how to get the server side Date

查看:48
本文介绍了如何获得服务器端日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我开发了一个使用ASP.NET和VB的在线系统,该系统正在制定旅行保险政策。我有一个今天日期字段。此字段显示客户端发布策略的今天日期,我希望获取服务器日期而不是客户端日期,因为客户端可能会更改其设备的日期并制定新策略。

< br $> b $ b



ASP.net Vb.NET



如何获取服务器边约会?











谢谢



i develop an online system with ASP.NET and VB which is issuing policies for travel insurance. i have a field for "Today" date. this field displays the today date in which the client issuing policies by, i want to get the server Date NOT the client side date because the client might change the date of his device and makes new policies.



ASP.net Vb.NET

how to get the server side date ??





thanks

推荐答案

如果您使用
var dt = DateTime.Now;

那么您将获得日期运行代码的服务器。

then you will get the date on the server as that is where the code is run.


在发布后检查服务器端的日期可能更容易。然后,您可以添加日期未经服务器验证的响应。请检查您的系统日期或联系您的IS支持。



如果您需要日期在客户端,我建议在页面加载时添加正确的日期,并采用与系统日期相比较的日期。然后,您可以在帖子上应用此更改。这不会阻止客户端系统时钟在页面加载后被更改,因此您仍然需要先选择。



最后,您可以调用服务器使用ajax webservice调用从javascript开始的日期。这可以同步或异步完成,这样您就可以在页面加载和页面提交之前获取日期。我不建议轮询,因为这可能是连接繁重的。



最后一种方法是使用signalR,这是一种非常有用的异步服务,可以推送或提取数据服务器。这在连接上要轻得多(每个浏览器额外增加1个),但很可能是大规模的矫枉过正。



如果您需要帮助解决所选择的解决方案,请告诉我^ _ ^



Andy
It might be easier to just check the date at the server side after they post. You can then add a response that "The date was not validated by the server. Please check your system date or contact your IS Support."

If you need the date on the client side, I suggest adding the correct date on page load and taking a datediff of that compared to the system date. You can then apply this alteration on post. This doesn't stop the client side system clock being changed after the page is loaded so you will still need to first option.

Lastly, you can call for the server date from javascript using an ajax webservice call. This can be done sync or async so you can get the date on page load and before page submit. I would not advise polling as this can be connection-heavy.

The last alternative is to use signalR which is a very useful async service that can push or pull data from the server. This is much lighter on connections (1 extra per browser) but is most likely massive overkill.

if you need help with your chosen solution then please let me know ^_^

Andy


你好,



有至少三种实现此目的的方法。

< oi>

  • 从ASP.NET页面输出一个JavaScript块

Hello,

There are at-least three ways to achieve this.
<oi>
  • Output a JavaScript Block from your ASP.NET Page
<script language="javascript">
function returnresponse() {
    document.getElementById("timediv").innerText="<%=DateTime.Now %>";
}
</script>

  • 动态创建客户端脚本(更多 [ ^ ])

  • Create client script dynamically (more[^])
void Page_Load(object sender, EventArgs e)
{
    String scriptText = "";
    scriptText = "var svrDate = '" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "';";
    ClientScriptManager.RegisterClientScriptBlock(this.GetType(), "DateTimeScript", scriptText, true);
}

  • 创建日期时间服务并使用AJAX调用它。 (更多 [ ^ ])
  • Create a date time service and invoke it using AJAX. (more[^])


这篇关于如何获得服务器端日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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