服务器上的DateTime差异 [英] DateTime difference on server

查看:85
本文介绍了服务器上的DateTime差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我有一个有关DateTime的问题.在我的页面上,我正在使用Javascript显示日期,当我根据该日期时间保存某些内容时,它会根据服务器时间进行保存.这给我造成了问题.假设用户在印度,服务器在美国,则可以通过浏览器看到日期时间.但是当他保存该值时,它取决于服务器时间,比印度时间少12小时.

请让我知道如何解决此问题.

谢谢,
Jagjot

Hello Friends,

I have an issue regarding DateTime. On my page, I am showing date by using Javascript, when I save something according to that datetime, it saves according to Server time. It is causing an issue for me. Suppose a user is in India and server is in US, he can see the datetime as per his browser. But when he saves the value, it is according to server time, which is 12 hours less than India time.

Please let me know how I can come up of this issue.

Thanks,
Jagjot

推荐答案

出了什么问题?您不仅需要了解客户观察的时间,还需要了解其时区,可以在创建帐户或诸如此类的过程中请求它.

或者,您可以忽略本地客户端时间,仅按服务器时间计算所有时间.这取决于您的要求.

在这两种情况下,都可以通过使用System.DateTime.ToUniversalTime将所有时间转换为世界标准时间来进行所有时间的计算.如果需要使用客户端的本地时间在页面上显示时间,则可以在使用System.DateTime.ToLocalTime为每个时区分别生成页面的同时进行显示.同样,您将需要知道每个客户端的时区.

请参阅以获取更多信息: http://msdn.microsoft.com/en-us/library/system .datetime.aspx [^ ].

-SA
What''s the problem? You need to know not just the time by client watch but also its time zone, can be requested during creation of account or something like that.

Alternatively, you can ignore local client time and calculate all times by the server time only. It depends on your requirements.

In both cases, it''s convenient to do all time calculation by converting all times into Coordinated Universal Time using System.DateTime.ToUniversalTime. If you need to present time on the page using client''s local time, you can do it while generating a page individually for each time zone using System.DateTime.ToLocalTime. Again, you will need to know a time zone of each client.

See for more information: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA


您可能希望将值从客户端传递到服务器-不要让服务器保存默认日期.
您也可以考虑使用UTC日期时间来避免此问题.
You might want to pass your value from the client to the server - don''t let the server save a default date.
You can also consider using UTC datetimes to help avoid this problem.


这篇关于服务器上的DateTime差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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