从GAE服务器发送日期和时区到GWT客户端 [英] Sending a date and timezone from GAE server to GWT client

查看:87
本文介绍了从GAE服务器发送日期和时区到GWT客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的人们,我一直在解决这个问题大约2周,现在试着我能想到的一切,并在这里看到大量的答案,他们觉得他们会回答它,但我不能解决我如何我的意思是做我想做的事情,它绝对让我坚强!似乎没有人能够在任何地方得到答案,全球各地都有一半的答案,但似乎没有人真正做到我需要做的事情,肯定有人会解决这个问题!请原谅真正长期的问题,但重要的是要问这个问题是正确的,以便答案能够真正回答这个问题! :D





如果您可能提供任何答案,请不要再进一步阅读没有考虑到我的数据存储/服务器是Google App Engine(GAE),而我的客户端是用Google Web Toolkit(GWT)编写的,一切都是用Java编写的,我不知道任何有关Python或MySQL或PHP的内容或类似的东西那最后如果有人知道一个更好的地方这样的东西出来,请让我知道,因为我不断提出这样的问题,并不知道如何在这里寻找解决方案以外的其他解决方案,或者花费数小时搜索谷歌,找到已经设法解决问题的其他人。我也不知道如何从JavaDocs中找出任何东西 - 抱歉,但直到有人向我解释它,我只是不会得到它。



我有一个日期时间存储在服务器(显然是UTC)我还在服务器上为每个业务所有者存储了一个时区作为字符串存储(例如America / New_York)。该字符串通过在服务器上使用 java.util.TimeZone.getAvailableIDs()获得,并让业务所有者为其业务选择相关时区(默认值为欧洲/伦敦如果他们没有选择任何东西 - 不需要挂上那个位)我需要在将来的某个时间将任何日期时间传递回客户端PC ,因为日期时间需要根据企业主的时区显示,所以在他们的个人电脑上忽略当地时区。

所以作为一个例子,企业主是理发师在伦敦,他们有一个网上预约时间表,任何他们的潜在客户都可以查看。其中一位客户(也是在伦敦)想要预约,9月3日星期一在BST上午9点看到一个位置,并预订它。

然后将这些信息存储在数据存储作为UTC时间(实际上0800,因为BST是UTC + 1),当然企业所有者已经选择了Europe / London作为他们的时区。一切都很好。



现在,在未来某个时候,客户正在纽约举行一次商务会议,并意识到他们在下周有一个预约在伦敦理发,他们想把它移动一周,所以他们然后试图查看约会(在理发师的约会书),但他们不希望看到它作为纽约时间凌晨4点,他们想看到因为我的问题是,当客户在9月3日点击查看约会时,服务器可以发回0800的UTC日期时间和 java.util.TimeZone Europe / London的字符串



但是因为在客户端我只能使用

  com.google.gwt.i18n.client.TimeZone 

它不允许我使用函数

<$
(适用于`java.util.TimeZone`)
pre $ TimeZone bizTimeZone = TimeZone.getTimeZone(Europe / London

,因为它会导致错误

 方法getTimeZone字符串)未定义类型TimeZone

建议将其更改为

  com.google.gwt.i18n.client.TimeZone.createTimeZone(Europe / London)

但是这个版本需要一个GWT com.google.gwt.i18n.client.TimeZoneConstants 对象(在此消息的末尾显示示例),而不是 java.util.TimeZone.createTimeZone()将接受的简单字符串。



我可以通过以下方式创建它:

  final TimeZoneConstants constTz = GWT.create(TimeZoneConstants.class ); 
final TimeZone timeZoneCali = TimeZone.createTimeZone(constTz.europeLondon());

但是当我以开始时,我不知道如何做到这一点欧洲/伦敦和/或我不知道如何将这个对象存储到App Engine数据库中,然后再检索它。



顺便说一句,文本我也尝试使用以下几行:

  //日历tmad =新格雷戈里安日历(TimeZone.getTimeZone(Europe / London )); 
//日历cal = Calendar.getInstance(someTimeZone);
// DateFormat df1 = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);
//df1.setTimeZone(TimeZone.getTimeZone(\"Europe/London));
// final TimeZone timeZoneClient = TimeZone.createTimeZone(Europe / London);
//dtf.format(date,timeZoneClient)

必须有一个标准的方法这样做,我真的不能成为第一个解决这个问题的人!


constTz.europeLondon()= {transitions :[19394,60,24770,0,283030,
60,33506,0,36866,60,42242,0,45602,60,50978,0,54506,60,
59714,0 ,63242,60,68450,0,71978,60,77354,0,80714,60,86090,
0,89450,60,94826,0,98521,60,103561,0,107257,60,112297 ,0,
115993,60,121033,0,124729,60,129937,0,133633,60,138673,0,
142369,60,147409,0,151105,60,156145,0 ,159841,60,164881,0,0
168577,60,173785,0177313,60,182521,0,186217,60,191257,0,0
194953,60,19993,0,0203689 ,60,208729,0,221425,60,217465,0,0
221161,60,26201,0,230065,60,235105,0,238801,60,243841,0,
247537,60 ,252577,0,26273,60,261481,0,265009,60,270217,0,
273745,60, 278953,0,282649,60,287689,0291385,60,296425,0,
300121,60,305329,0,308857,60,314065,0,3177593,60,322801,0,
326329,60,331537,0,335233,60,340273,0,343969,60,349009,0,
352705,60,357913,0,361441,60,366649,0,370177,60, 375385,0,
379081,60,384121,0,387817,60,492857,0,396553,60,401593,0,0
405289,60,410497,0,414025,60,419233, 0,422761,60,427969,0,0
431665,60,436705,0440401,60,445441,0449137,60,4454345,0
457873,60,463081,0, 466609,60,471817,0,475513,60,480553,0,
484249,60,489289,0,492985,60,498025,0,501721,60,506929,0,
510457, 60,515405,0519193,60,534073,0,528097,60,53137,0,
536833,60,541873,0,5545569,60,550777,0,554305,60,559513,0,
563041,60,568249,0,571777,60,576985,0,580681,60,585721,0,
589417,60,594457,0],names:[GMT, 格林威治标准时间,BST,
英国夏令时] ,id:Europe / London,std_offset:0}


解决方案

我对v2.4有类似的问题。



我认为Riley Lark是正确的。
$ b

TimeZone.createTimeZone(Asia / Tokyo) 在GWT 2.4中无法使用



然而,我发现我可以通过浏览器的默认设置获取东京区域:

  Date d = new Date(); 
TimeZone timezone = TimeZone.createTimeZone(d.getTimezoneOffset());

由于europeLondon有std_offset:0,这就是Riley Lark给你建议的内容。


TimeZone timezone = TimeZone.createTimeZone(0);


OK folks, I have been going around this problem for about 2 weeks now trying everything I can think of and looking at tons of answers on here that feel like they are going to answer it, but I just cant work out how I am meant to do what I am trying to do and it is driving me absolutely NUTS! No one seems to have an answer anywhere, there are half answers all over the place, but none seem to actually do what I need it to do, surely SOMEONE has solved this problem before! Please excuse the REALLY long question, but its important that the question is asked right, so that the answers actually answer the need! :D

Also please don't bother reading any further if you are likely to provide any answer which does not take into account that my datastore/server is Google App Engine (GAE), and my Client is written in Google Web Toolkit (GWT) and everything is written in Java, I dont know anything about Python or MySQL or PHP or anything like that

Finally if anyone knows of a better place to figure stuff out like this, PLEASE do let me know as I keep coming up with issues like this and have no idea how to find a solution other than in here, or spend hours and hours searching google for someone else who has already managed to figure it out. I also dont understand how to figure anything out from JavaDocs - sorry, but until someone explains it to me, Im just not going to get it

I have a datetime stored on the server (in UTC obviously) I also have stored on the server a TimeZone for each business owner stored as a string (eg "America/New_York"). This string is obtained by using java.util.TimeZone.getAvailableIDs() on the server and getting the business owner to select the relavant timezone for their business (default is "Europe/London" if they don't choose anything - no need to get hung up on that bit) I need to pass any datetimes back to the client PC at some point in the future, IGNORING the local timezone on their PC, because the datetime needs to be displayed according to the timezone of the business owner.

So as an example the business owner is a hairdressers in London and they have an online appointment schedule which is available to be viewed by any potential customer of theirs. One of these customers (also in London) wants to book an appointment, sees a slot at 9am BST on Monday 3rd September and books it.

This is then stored in the Datastore as the UTC time (which is actually 0800 as BST is UTC+1), and of course the business owner has selected "Europe/London" as their timezone. Everything fine so far.

NOW, at some point in the future, the customer is on a business meeting in New York, and realises that they have an appointment the following week for a haircut in London and they want to move it by a week, so they then try to VIEW the appointment (in the hairdressers appointment book), but they don't want to see it as 4am New York Time, they want to see it as 9am British time.

So my problem is that when the customer clicks to VIEW appointments on 3rd September, the server can send back a UTC datetime of 0800 and a java.util.TimeZone ID String of "Europe/London"

But because on the client I can only use

com.google.gwt.i18n.client.TimeZone

it doesn't allow me to use the function

TimeZone bizTimeZone=TimeZone.getTimeZone("Europe/London")
(which works for `java.util.TimeZone`)

as it causes the error

"The method getTimeZone(String) is undefined for the type TimeZone"

it suggests changing it to

com.google.gwt.i18n.client.TimeZone.createTimeZone("Europe/London")

but this version, is expecting a GWT com.google.gwt.i18n.client.TimeZoneConstants "object" (example shown at the end of this message) and not the simple string that the java.util.TimeZone.createTimeZone() will accept.

I can create this by using:

final TimeZoneConstants constTz = GWT.create(TimeZoneConstants.class);
final TimeZone timeZoneCali = TimeZone.createTimeZone(constTz.europeLondon());

But I dont know how to do this when Im starting with "Europe/London" and/or I dont know how to store this object into the App Engine DataBase and then retrieve it later.

Incidentally amongst the commented text I have also tried using the following lines:

//Calendar tmad = new GregorianCalendar(TimeZone.getTimeZone("Europe/London"));
//Calendar cal = Calendar.getInstance(someTimeZone);
//DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//df1.setTimeZone(TimeZone.getTimeZone("Europe/London"));
//final TimeZone timeZoneClient = TimeZone.createTimeZone("Europe/London");
//dtf.format(date,timeZoneClient)

There MUST be a standard way of doing this SURELY, I really cant be the first person to ever have to solve this issue!

constTz.europeLondon()={"transitions": [19394, 60, 24770, 0, 28130, 60, 33506, 0, 36866, 60, 42242, 0, 45602, 60, 50978, 0, 54506, 60, 59714, 0, 63242, 60, 68450, 0, 71978, 60, 77354, 0, 80714, 60, 86090, 0, 89450, 60, 94826, 0, 98521, 60, 103561, 0, 107257, 60, 112297, 0, 115993, 60, 121033, 0, 124729, 60, 129937, 0, 133633, 60, 138673, 0, 142369, 60, 147409, 0, 151105, 60, 156145, 0, 159841, 60, 164881, 0, 168577, 60, 173785, 0, 177313, 60, 182521, 0, 186217, 60, 191257, 0, 194953, 60, 199993, 0, 203689, 60, 208729, 0, 212425, 60, 217465, 0, 221161, 60, 226201, 0, 230065, 60, 235105, 0, 238801, 60, 243841, 0, 247537, 60, 252577, 0, 256273, 60, 261481, 0, 265009, 60, 270217, 0, 273745, 60, 278953, 0, 282649, 60, 287689, 0, 291385, 60, 296425, 0, 300121, 60, 305329, 0, 308857, 60, 314065, 0, 317593, 60, 322801, 0, 326329, 60, 331537, 0, 335233, 60, 340273, 0, 343969, 60, 349009, 0, 352705, 60, 357913, 0, 361441, 60, 366649, 0, 370177, 60, 375385, 0, 379081, 60, 384121, 0, 387817, 60, 392857, 0, 396553, 60, 401593, 0, 405289, 60, 410497, 0, 414025, 60, 419233, 0, 422761, 60, 427969, 0, 431665, 60, 436705, 0, 440401, 60, 445441, 0, 449137, 60, 454345, 0, 457873, 60, 463081, 0, 466609, 60, 471817, 0, 475513, 60, 480553, 0, 484249, 60, 489289, 0, 492985, 60, 498025, 0, 501721, 60, 506929, 0, 510457, 60, 515665, 0, 519193, 60, 524401, 0, 528097, 60, 533137, 0, 536833, 60, 541873, 0, 545569, 60, 550777, 0, 554305, 60, 559513, 0, 563041, 60, 568249, 0, 571777, 60, 576985, 0, 580681, 60, 585721, 0, 589417, 60, 594457, 0], "names": ["GMT", "Greenwich Mean Time", "BST", "British Summer Time"], "id": "Europe/London", "std_offset": 0}

解决方案

I have a similar issue with v2.4.

I think Riley Lark is right.

TimeZone.createTimeZone("Asia/Tokyo") did not work in GWT 2.4

However, I found I could get the Tokyo zone by using the browser's default setting via:

Date d = new Date();
TimeZone timezone = TimeZone.createTimeZone(d.getTimezoneOffset());

That is really what Riley Lark is suggesting for you since europeLondon has "std_offset": 0...

TimeZone timezone = TimeZone.createTimeZone(0);

这篇关于从GAE服务器发送日期和时区到GWT客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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