×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Getting the current time is timezone dependent on S60 2nd Edition (Known Issue)

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Removed protection from "KIJ000085 - Getting the current time takes the TimeZone into account": Merging into Wiki)
hamishwillee (Talk | contribs)
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{Archived|timestamp=20120608175031|user=[[User:Lpvalente|Lpvalente]]}}
 +
[[Category:Known Issue]][[Category:Java ME]][[Category:S60 2nd Edition (initial release)]]
 +
 +
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
Line 26: Line 30:
  
 
==Description==
 
==Description==
CLDC 1.0 specification requires the method System.currentTimeMillis() to return the time in UTC (GMT).
+
{{Abstract|CLDC 1.0 specification requires the method System.currentTimeMillis() to return the time in UTC (GMT).}}
  
 
Because some earlier phone models supported only time zone UTC, MIDlet programmers did not always take the difference between UTC and local time into account. MIDlets did work correctly assuming that the returned value was in local time, without even checking time zone settings.
 
Because some earlier phone models supported only time zone UTC, MIDlet programmers did not always take the difference between UTC and local time into account. MIDlets did work correctly assuming that the returned value was in local time, without even checking time zone settings.
Line 35: Line 39:
 
Use a Calendar object to get the local time.
 
Use a Calendar object to get the local time.
  
Calendar calendar = Calendar.getInstance() ;&nbsp; // uses default TimeZone<br>Calendar.setTime( new Date( System.currentTimeMillis()) ;
+
<code java>
 +
Calendar calendar = Calendar.getInstance() ; // uses default TimeZone
 +
Calendar.setTime( new Date( System.currentTimeMillis()) ;
 +
</code>
  
 
Note: The phone user can set the time zone as follows:
 
Note: The phone user can set the time zone as follows:
  
1. By turning the automatic time update on. This is a network service and is not supported in all networks.
+
By turning the automatic time update on. This is a network service and is not supported in all networks.
 +
#  By setting the time zone manually in the Clock application or under Settings / Date & Time.
  
2. By setting the time zone manually in the Clock application or under Settings / Date & Time.
 
  
 
MIDlet programmers should be aware that Java applications are just about the only application in the phone that uses the time zone. Thus, users might have incorrect time zone settings in their phone without being aware of it.
 
MIDlet programmers should be aware that Java applications are just about the only application in the phone that uses the time zone. Thus, users might have incorrect time zone settings in their phone without being aware of it.
 
[[Category:Known Issue]][[Category:Java ME]][[Category:S60 2nd Edition (initial release)]]
 

Revision as of 04:55, 19 June 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata
Tested with
Devices(s): Nokia 6600
Compatibility
Platform(s): S60 2nd Edition
S60 2nd Edition (initial release)
Article
Created: User:Technical writer 1 (20 Aug 2007)
Last edited: hamishwillee (19 Jun 2012)

Description

CLDC 1.0 specification requires the method System.currentTimeMillis() to return the time in UTC (GMT).

Because some earlier phone models supported only time zone UTC, MIDlet programmers did not always take the difference between UTC and local time into account. MIDlets did work correctly assuming that the returned value was in local time, without even checking time zone settings.

In the Nokia 6600 device such existing MIDlets might behave differently, using UTC instead of local time as expected in many use cases.

Solution

Use a Calendar object to get the local time.

Calendar calendar = Calendar.getInstance() ;  // uses default TimeZone
Calendar.setTime( new Date( System.currentTimeMillis()) ;

Note: The phone user can set the time zone as follows:

  1. By turning the automatic time update on. This is a network service and is not supported in all networks.
  2. By setting the time zone manually in the Clock application or under Settings / Date & Time.


MIDlet programmers should be aware that Java applications are just about the only application in the phone that uses the time zone. Thus, users might have incorrect time zone settings in their phone without being aware of it.

80 page views in the last 30 days.
×