473,574 Members | 2,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date calculations in multiple time zones

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.Calen dar 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

Sep 14 '05 #1
11 4632
> What approach can I use to make the calculations match
the currently selected time zone?


currently selected timezone where ??
Sep 14 '05 #2

<ld*******@gmai l.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
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.Calen dar 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?


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.

Sep 14 '05 #3
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

Sep 15 '05 #4
In the backend, that's what happens. Java has pretty good Timezone
handling
capabilities. My problem is getting the Javascript display to do what
the Java
backend does: dissociate the date display from the actual time value.

In Javascript, there are two date formats: local time and UTC time. It
looks to
me like I can't deal with dates in an arbitrary time zone. It looks to
me like
dealing with arbitrary time zones requires some outside intervention
from me,
to tell Javascript how to deal with that issue.

My code looks like this:

/**
* I have a percentage box. When the user modifies that value, dates
and
* times are modified in the form.
*/
function updateDatesAndT imes(objForm, objPercent) {

pct = objPercent.valu e;
if (pct>100) {
pct = 100;
objPercent.valu e=100;
} else if (pct < 0) {
pct = 0;
objPercent.valu e=0;
}

// Update distance
objForm.actv_di stance.value=or igDistance * pct / 100;

objForm.actv_di stance2.value=o rigDistance-objForm.actv_di stance.value;
objForm.actv_od o_value.value=o rigOdoValue -
objForm.actv_di stance2.value;

// Update dates and times
==> // actvBeginTime contains a date in milliseconds value
updateTime = new Date();
updateTime.setT ime(actvBeginTi me + (actvElapsedTim e * pct /100));
==> // Here, the date and time values are displayed for the user. This
is where my problem
// occurs because I am not displaying in the correct time zone.
form.displayDat e2.value = formatDateAsDat e(updateTime,
objForm.beginDa te2);
form.beginTime2 .value = formatDateAsTim e(updateTime);

// update duration times
form.legDuratio n.value = formatTime(actv ElapsedTime * pct /100);
form.legDuratio n2.value = formatTime(actv ElapsedTime -
(actvElapsedTim e * pct /100));

}
/**
* Return the time of day for a given date in HH:mm::ss format.
* The value must change according to the time zone in effect. The time
* zone is not necessarily the client time zone nor GMT/UTC.
*/
function formatDateAsTim e(time) {
var hour = time.getHours() ;
var minute = time.getMinutes ();
var second = time.getSeconds ();
var temp = ((hour < 10) ? "0" : "") + hour;
temp += ((minute < 10) ? ":0" : ":") + minute;
temp += ((second < 10) ? ":0" : ":") + second;
return temp;
}

L

Sep 15 '05 #5

ld*******@gmail .com wrote:
My code looks like this:


Ahh! Someon just gave me an idea: change the Locale for my request to
reflect the time zone I want to use. If I do that, I can use local
timezone all the time and the data display and calculations will be
correct.

I'll try that.

L

Sep 15 '05 #6

<ld*******@gmai l.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .

ld*******@gmail .com wrote:
My code looks like this:


Ahh! Someon just gave me an idea: change the Locale for my request to
reflect the time zone I want to use. If I do that, I can use local
timezone all the time and the data display and calculations will be
correct.


which will lonly work if the clients machine is set up the same way...
Sep 15 '05 #7

Zoe Brown wrote:
Ahh! Someon just gave me an idea: change the Locale for my request to
reflect the time zone I want to use. If I do that, I can use local
timezone all the time and the data display and calculations will be
correct.
which will lonly work if the clients machine is set up the same way...


Yep... I'm realising that the locale isn't enough. What I'm leaning
towards is to add the timezone offset in the request and use that on my
page to display it correctly. IOW, in the function that formats dates
to display, I'll pad the time value witht the timezone offset value.From there, I'll be able to affect only the display, while all the

calculations remain correct.

I'm working on it from that angle.

L

Sep 15 '05 #8
JRS: In article <11************ *********@f14g2 000cwb.googlegr oups.com>,
dated Wed, 14 Sep 2005 13:40:22, seen in news:comp.lang. javascript,
ld*******@gmail .com posted :
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.
Please explain why reading the newsgroup FAQ has not helped you.

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.


EDT is not a time zone. Time zones are geographical areas, which exist
the whole year round.

TLAs (other than GMT and UTC) are not adequate to describe either zones
or offsets from UTC; EST has at least two meanings and BST at least
three.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 15 '05 #9
JRS: In article <11************ **********@g47g 2000cwa.googleg roups.com>
, dated Thu, 15 Sep 2005 06:57:28, seen in news:comp.lang. javascript,
ld*******@gmail .com <ld*******@gmai l.com> posted :
Ahh! Someon just gave me an idea: change the Locale for my request to
reflect the time zone I want to use. If I do that, I can use local
timezone all the time and the data display and calculations will be
correct.


That's a really stupid idea if running in a system (such as Windows)
where many processes run at once. Any other time-dependent process may
get confused, especially appointments software.

It might be safe enough in a intranet on which all machines were DOS.

Read the Newsgroup FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5207
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
5
2298
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from another time zone. It would be of great value if the time of some central source could be drawn, in the form of a ".js" file, into the script to avoid...
13
2216
by: Dr John Stockton | last post by:
Javascript date strings can have a one-letter postfix; it is taken as indicating time zone (not J, which causes NaN). // IIRC, VB accepts A & P in that location, for AM & PM. In my MS IE 4, the object generated by new Date("2001/1/1 0:0:0R") has value meaning Sun Dec 31 19:00:00 UTC 2000. That combination of local...
14
3655
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be...
13
16140
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to local time from UTC function formatToLocalTimeDate(inDate) { var today = new Date(); var inDateMod = new Date(inDate);
3
2077
by: C Villalba | last post by:
Birth Date and a Purchase Date aata is being stored in sql. This information is retrieved across time zones through a .Net Web Service. When the data is viewed in a .Net client application these dates are shifted due to time zone differences. Anyone know the best way to stop this ffrom happening?
44
10162
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
3
1809
by: rharmonster | last post by:
I have a web page programmed in ASP that creates a calling list based on the user's preferences, which queries the information from a SQL 2000 database. I want the user to be able to select whether to create different lists based on time zones or one list with all time zones. The user should be able to mix and match time zones. However, I'm...
10
4008
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one problem. This function does not recognize time zones. How to adjust date to user's time zone? Is converting to timestamp() and then to format...
0
7815
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8078
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7829
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5319
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3755
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3766
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.