在不同的时区工作 [英] work on different time zone

查看:82
本文介绍了在不同的时区工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这里客户端意味着我们的客户端。客户端意味着我们这个应用程序的客户端,而不是网络编程服务器 - 客户端的客户端。)





我们在asp.net中有一个客户支持Web应用程序。现在,假设我们的客户在英国。那么所有系统都将在英国时区运行,而不管服务器保留页面的时间。



提供服务设置在下午5点。然后,当支持成员搜索该服务时,即使他在印度,他也会在下午5点看到该服务。时间不会被转换。



还需要设置日历控件,通常会获取用户的日期时间,以便它可以显示我们客户的时区时间和日期。



另外我不能使用服务器日期时间,因为服务器可能在客户端的不同时区。我可以进行计算以将服务器时间转换为客户端时间。但是如果客户端更改了他的服务器,那么?我必须重写计算。 />


在一个句子中,完整的系统,输出和输入,这些将在客户的时区。首先我们必须在我的应用程序中设置客户时区,然后给他这个应用程序,然后所有应用程序将在他的时区工作。



那么该如何做呢?任何人都可以提出任何想法吗?如果我的思路方式错误,你可以轻松地说出来。

解决方案

是的,这正是UTC计时跳入并节省您的地方。



https://en.wikipedia.org/wiki/Coordinated_Universal_Time [ ^ ]



您可以使用此时间在UTC时间内保存所有处理时间,只需将时间添加到DateTime。这样,服务器上的时间将是相同的,但客户端会通过添加(或减去)小时,分钟等来查看其区域时间的时间。



你可能会好奇,Facebook上的一篇文章是在UTC时间上午12:00发布的,它在太平洋标准时间凌晨5点向我展示,怎么样?因为他们只是节省了5个小时的时间,所以这样的事情



  //  你可以在5的位置使用变量 
DateTime dateForClient = dateOnServer.AddHours( 5 );





我有一个工作小提琴,你可以测试这个过程。 https://dotnetfiddle.net/KFBSDJ [ ^ ]



祝你好运。


您也可以随时跟踪在UTC中并使用客户端上的转换来使用本地时间显示日期(使用javascript)。如果您要获取某些内容的日期,客户端可以在javascript中生成一个utc日期并将其传递给服务器。



这种方法的优点是它会使用任何时区。



这篇文章有一些讨论,应该是一个好的开始。



http://stackoverflow.com/questions/4631928/convert-utc -epoch-到本地日期与JavaScript的

(Here client means our client.Client side means the side of our client of this app,not the web programming server-client's client.)


We have an customer support web app in asp.net. Now, say our client is in UK.Then all the system will be operated in uk time zone irrespective of server time on which the pages are kept.

Let a service is set in 5pm uk time.Then when a support member search for that service,he will see the service is set on 5pm even if he is in India.Time will not be converted.

also the calender controls,which generally fetch user's datetime, have to be set so that it can show our clients time zone time and date.

Also I can not use server datetime, as the server may be in different timezone as of client.I can make a calculation to convert server time to our client time.But if client changes his server,then?I have to rewrite calculation.

In a sentence,full system,outputs and inputs whatever,those will be in clients time zone.At first we have to set clients time zone in my app before giving him this app,then all the app will work in his time zone.

So how to do it?Can anyone give any idea?Also you can tell any easy way if I'm thinking in wrong way.

解决方案

Yes, and that is exactly where UTC timing jump in and saves you.

https://en.wikipedia.org/wiki/Coordinated_Universal_Time[^]

You can use this timing to save all of the processing times in the UTC time, and just Add Hours to the DateTime. This way, the timing on the server would be same, but the client would see the time in his locale time by adding (or subtracting) hours, minutes etc.

You can wonder it like, a post on Facebook was posted by me at 12:00 AM UTC, and it was shown to me at 5:00 AM PST, how? Because they just added 5 hours to the time that was saved, something like this

// you can use variable in the place of 5
DateTime dateForClient = dateOnServer.AddHours(5);



I am having a working fiddle for you, where you can test this process. https://dotnetfiddle.net/KFBSDJ[^]

Good luck.


You could also simply track all time in UTC and use conversions on the client to display the date using local time (using javascript). If you are obtaining the date for something, the client can generate a utc date in javascript and pass it to the server.

The advantage of this approach is that it will work with any timezone.

This article has some discussion about it and should be a good start.

http://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript


这篇关于在不同的时区工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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