BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-21-2009, 12:32 PM   #1 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Calendar/Time Zone question

Please Login to Remove!

Can someone please tell what I should expect to see in the calendar for the following statements?

TimeZone _tz = TimeZone.getTimeZone("GMT-08");
Calendar _cal = Calendar.getInstance(_tz);


I would expect to see the time zone time with

long _CalendarTime = _cal.getTime().getTime();

for time zone GMT-08 but I do not.
Offline  
Old 09-21-2009, 01:02 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

From the javadocs:

Gets this Calendar's current time as a long expressed in milliseconds after January 1, 1970, 0:00:00 GMT (the epoch).
Offline  
Old 09-21-2009, 01:06 PM   #3 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Understood.

What is the purpose of getInstance("GMT-8:00")?
Offline  
Old 09-21-2009, 06:48 PM   #4 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

The time zone is used for the "Calendar" data atttributes, like DAY, WEEK, YEAR, etc.

This particular method is used to retrieve the GMT expressed as a number of milliseconds since 1/1/70.
Offline  
Old 09-21-2009, 09:18 PM   #5 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

So if I do a getInstance("GMT-8:00") then getTimeInMillis() I should have the total milliseconds for "GMT-8:00"?

If your answer is "yes" then this is not the value I see returned.
Offline  
Old 09-21-2009, 10:53 PM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

getTimeMillis returns the time in GMT - as it states in the docs.
Offline  
Old 09-22-2009, 07:57 AM   #7 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know this but when I do a getInstance("GMT-08:00") then getTimeMillis it is not GMT-08:00 but the current time the device is set to. See my first posting for the way I am coding this.
Offline  
Old 09-22-2009, 08:56 AM   #8 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

I don't understand the confusion.

The docs clearly state that this particular method returns the time in GMT.

Why do you expect it to do otherwise?

Maybe I just do not understand your issue?

Last edited by Dougsg38p : 09-22-2009 at 09:07 AM.
Offline  
Old 09-22-2009, 10:38 AM   #9 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe I'm not explaining this right so let me try again...

My device time/time zone is set to "America/New_York" or GMT-05:00.
I do Calendar _cal = Calendar.getInstance("America/Los_Angeles"). Since I specified the time zone with getInstance I would expect _cal.getTime().getTime() to return the milliseconds for "America/Los_Angeles" or GMT-08:00. It does not. It returns the milliseconds for America/New_York" which is GMT-05:00.

How can I get it to return milliseconds for "America/Los_Angeles" or GMT-08:00?
Offline  
Old 09-22-2009, 10:41 AM   #10 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

How are you determining this? Can you post a code snippet that demonstrates the issue?
Offline  
Old 09-22-2009, 10:51 AM   #11 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Calendar/Time Zone question

Calendar _cal = Calendar.getInstance("America/Los_Angeles");
long lCalendarTime = _cal.getTime().getTime();
Date _date = new Date(lCalendarTime);
Dialog.inform(_date.toString());


Displays "America/New_York" time.

Am I missing something?
Offline  
Old 09-22-2009, 12:58 PM   #12 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

The time variable is stored internally as GMT.

The Date.toString() is going to format the date based on the default timezone setting for the device.

From my experience, this is expected behavior.
Offline  
Old 09-22-2009, 01:17 PM   #13 (permalink)
New Member
 
Join Date: Jul 2009
Model: 9530
PIN: N/A
Carrier: Verizon
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, then where should I see the time in milliseconds for "America/Los_Angeles"? I still think the calendar I declare with getInstance("America/Los_Angeles") should be returning this time instead of the device time.
Offline  
Old 09-22-2009, 01:50 PM   #14 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

I understand your argument, but that is not the way this works.

Here is the deal:

* All dates are stored as the GMT value, not a time-zone adjusted value.
* The date (once retrieved) is displayed or viewed as the local adjusted value for the time zone, or the default device time zone.
* The "getCurrentMillis()" methods are going to return you the "raw" GMT time, because the other API's will adjust your *view* of this data to the local zone.

In your Calendar example above, try getting and printing out the various discrete date components (DAY, MONTH, etc). I think you will find that these will come back to you adjusted for the timezone you requested in the getInstance() method.

Perhaps if you can explain what you are trying to accomplish, we can make a suggestion on how to get there.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.