多个时区的日期计算 [英] Date calculations in multiple time zones

查看:61
本文介绍了多个时区的日期计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我试图在三种时区进行日期计算:本地,

GMT和指定。我面临的问题是我需要能够在适当的时区指定一个日期,而且我有一段时间

这样做。


我创建了一个表格,我使用下拉菜单指定年,月,

日期,小时,分钟和秒。加载表单时,下拉菜单

必须显示当前时区类型的正确值。这个

代码可以运行(同一个下拉菜单与给定时间同步)。


当我提交表单时,数据被发送到Java返回结束。返回

结束将使用年,月,日,小时,分钟,秒值和

使用java.util.Calendar对象生成正确的日期。那个

部分也可以正常工作。


然而,Javascript日期计算并没有那么好用。在

精华中,这就是我想要的。让我们说它是美国东部夏令时下午4点00分,我在美国东部夏令时区的时间是美元。到目前为止,非常好。


如果我转到我的表格,请选择本地作为我的时区,我想要我的表格

在我的下拉列表中预先显示16,0和0。


如果我选择 GMT",我想要选择20,0和0。


如果我选择PST,我想要选择13,0和0。


在我的表单上,我有一些我可以更改的值,它将执行某些

间隔计算,这些计算将发布到我的Java后端。当我执行这些计算时,必须根据当前

选择的时区来完成,否则它将无法给出
$ b的正确值。 $ b后端。


我看到的问题是我所有的日期计算都是在当地时间使用

完成的。我可以使用什么方法使计算与当前选定的时区相匹配?


感谢您的帮助,


L

Hi,

I`m trying to do date calculations in three types of time zones: local,
GMT and specified. The issue I am facing is that I need to be able to
specify a date in the proper time zone, and I`m having a heck of a time
doing so.

I have created a form where I use drop downs do specify year, month,
date, hour, minute and seconds. When the form is loaded, the dropdowns
have to display the proper values for the current time zone type. This
code works (the one that syncs the dropdowns with a given time).

When I submit my form, the data is sent to a Java back end. The back
end will take the year, month, date, hour, minute, seconds values and
generate the proper date, using the java.util.Calendar object. That
part works fine also.

The Javascript date calculations, though, doesn''t work as well. In
essence, this is what I want. Let''s say it is 4:00:PM EDT and I am in
the EDT time zone. So far, so good.

If I go to my form, select "Local" as my time zone, I want my form to
show up with 16, 0, and 0 preselected in my dropdown lists.

If I choose "GMT", I want 20, 0, and 0 to be selected.

If I select "PST", I want 13, 0, and 0 to be selected.

On my form, I have some values that I can change that will do certain
interval calculations which will be posted to my Java backend. When I
do these calculations, they have to be done according to the currently
selected time zone or it will not give the proper values to the
backend.

The problem I am seeing is that all my date calculations are done using
my local time. What approach can I use to make the calculations match
the currently selected time zone?

Thanks for all help,

L

推荐答案

>我可以用什么方法使计算匹配
> What approach can I use to make the calculations match
当前选择的时区?




目前选择的时区在哪里?



currently selected timezone where ??




< ld ******* @ gmail.com>在消息中写道

news:11 ********************* @ f14g2000cwb.googlegro ups.com ...

<ld*******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...


我试图在三种类型的时区进行日期计算:本地,
GMT和指定。我面临的问题是我需要能够在适当的时区指定一个日期,而且我有一段时间
这样做。
我创建了一个表单,我使用dropdown指定年,月,
日期,小时,分钟和秒。加载表单时,下拉列表必须显示当前时区类型的正确值。这个
代码可以工作(将下拉列表与给定时间同步)。

当我提交表单时,数据被发送到Java后端。后面的
结束将使用java.util.Calendar对象获取年,月,日,小时,分钟,秒值并生成正确的日期。那个
部分也可以正常工作。

Javascript日期计算虽然不起作用。在本质上,这就是我想要的。让我们说它是美国东部时间下午4点00分,我在EDT时区。到目前为止,非常好。

如果我转到我的表单,请选择本地。作为我的时区,我希望我的表单在我的下拉列表中预先显示为16,0和0。

如果我选择GMT,我想要20,0 ,如果我选择PST,我想要选择13,0和0。

在我的表格上,我有一些我可以更改的值将执行某些间隔计算,这些计算将发布到我的Java后端。当我进行这些计算时,必须根据当前选定的时区进行,否则它将无法为
后端提供正确的值。

我看到的问题是我所有的日期计算都是使用
当地时间完成的。我可以使用什么方法使计算与当前选定的时区相匹配?
Hi,

I`m trying to do date calculations in three types of time zones: local,
GMT and specified. The issue I am facing is that I need to be able to
specify a date in the proper time zone, and I`m having a heck of a time
doing so.

I have created a form where I use drop downs do specify year, month,
date, hour, minute and seconds. When the form is loaded, the dropdowns
have to display the proper values for the current time zone type. This
code works (the one that syncs the dropdowns with a given time).

When I submit my form, the data is sent to a Java back end. The back
end will take the year, month, date, hour, minute, seconds values and
generate the proper date, using the java.util.Calendar object. That
part works fine also.

The Javascript date calculations, though, doesn''t work as well. In
essence, this is what I want. Let''s say it is 4:00:PM EDT and I am in
the EDT time zone. So far, so good.

If I go to my form, select "Local" as my time zone, I want my form to
show up with 16, 0, and 0 preselected in my dropdown lists.

If I choose "GMT", I want 20, 0, and 0 to be selected.

If I select "PST", I want 13, 0, and 0 to be selected.

On my form, I have some values that I can change that will do certain
interval calculations which will be posted to my Java backend. When I
do these calculations, they have to be done according to the currently
selected time zone or it will not give the proper values to the
backend.

The problem I am seeing is that all my date calculations are done using
my local time. What approach can I use to make the calculations match
the currently selected time zone?




一个小提示是尽可能保持这一点,做所有计算

和DB存储等在一个时区中,只需使用用户首选项即可显示





One small hint is to keep this as simple as possible, do all calculations
and DB storage ect in ONE timezone and just use the user preference for
display purposes.


在页面显示之前,用户必须选择要使用的时区。

有三种选择:GMT,本地和选择一个。

因此,一旦显示页面,显示的所有日期和时间值必须与所选时区匹配。同一个用户可以使用

不同的时区显示页面,但她必须重新加载页面。 IOW,你不能

选择在GMT中显示,然后加载页面,同时查看页面,

要求在当地时间显示。如果您想将页面视图从

GMT更改为本地时间,您必须先更改要使用的时区,然后

重新加载页面。


那更清楚了吗?


L

Before the page is displayed, the user must select a time zone to use.
There are three choices: GMT, local, and "pick one".

So once the page is shown, all the date and time values displayed must
match the selected timezone. A same user can display the page using a
different time zone, but she has to reload the page. IOW, you can''t
select to display in GMT, load the page then, while viewing the page,
ask to display in local time. If you want to change the page view from
GMT to Local time, you have to first change the time zone to use, then
reload the page.

Is that any clearer?

L


这篇关于多个时区的日期计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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