Namespaces
Variants
Actions
(Difference between revisions)

Converting time zones in Java ME

Jump to: navigation, search
m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
m (Hamishwillee - Add Abstract. Tidy wiki text)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Java ME]][[Category:Code Examples]][[Category:General Programming]][[Category:Series 40]][[Category:Symbian]][[Category:S60 3rd Edition (initial release)]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]][[Category:Series 40 6th Edition FP1]][[Category:Series 40 Developer Platform 2.0]][[Category:Nokia Belle]][[Category:Localization]]
__NOEDITSECTION__
+
{{Abstract|This code snippet demonstrates how to convert time zones. }}
{{KBCS}}
+
{{ArticleMetaData
+
|id=CS001199
+
|platform=S60 3rd Edition, S60 3rd Edition, FP1, S60 3rd Edition, FP2
+
|devices=Nokia E70, Nokia N78
+
|category=Java ME
+
|subcategory=Date/time/clock
+
|creationdate=December 9, 2008
+
|keywords=java.util.TimeZone, java.util.TimeZone.getAvailableIDs, java.util.TimeZone.getRawOffset
+
  
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
+
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= [[Media:Converting time zones in J2ME.zip]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= Nokia E70, Nokia N78, Nokia C3-01, Nokia Asha 306, Nokia E7-00
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.1 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java (beta)], [http://www.developer.nokia.com/info/sw.nokia.com/id/ec866fab-4b76-49f6-b5a5-af0631419e9c/S60_All_in_One_SDKs.html/ Nokia Symbian SDKs]
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= Series 40, S60, Nokia Belle
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->)
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Vltsoy]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= java.util.TimeZone, java.util.TimeZone.getAvailableIDs, java.util.TimeZone.getRawOffset
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20081127
 +
|author= [[User:Vltsoy]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001199
 
}}
 
}}
  
 
==Overview==
 
==Overview==
 
This code snippet demonstrates how to convert time zones.
 
  
 
A list of all supported time zones is shown on the screen. By choosing a time zone from the list, the user can see the time offset it has.
 
A list of all supported time zones is shown on the screen. By choosing a time zone from the list, the user can see the time offset it has.
Method <tt>TimeZone.getTimeZone()</tt> allows the application to retrieve the chosen Time Zone and method <tt>TimeZone.getRawOffset()</tt> is used to retrieve the raw time offset for the chosen time zone.
+
Method {{Icode|TimeZone.getTimeZone()}} allows the application to retrieve the chosen Time Zone and method {{Icode|TimeZone.getRawOffset()}} is used to retrieve the raw time offset for the chosen time zone.
  
 
==Source file: ConvertingTimeZones.java==
 
==Source file: ConvertingTimeZones.java==
  
 
<code java>
 
<code java>
 
 
import java.util.TimeZone;
 
import java.util.TimeZone;
 
import javax.microedition.lcdui.Command;
 
import javax.microedition.lcdui.Command;
Line 133: Line 137:
 
==Supplementary material==
 
==Supplementary material==
  
The source file and executable application are available for download at [[Media:Converting_time_zones_in_J2ME.zip]].
+
The source file and executable application are available for download at [[Media:Converting time zones in J2ME.zip]].
 
+
[[Category:Java ME]][[Category:Code Examples]][[Category:Code Snippet]]
+

Latest revision as of 09:30, 5 October 2012

This code snippet demonstrates how to convert time zones.

SignpostIcon Code 52.png
SignpostIcon Localization 52.png
Article Metadata

Code Example
Tested with
Devices(s): Nokia E70, Nokia N78, Nokia C3-01, Nokia Asha 306, Nokia E7-00

Compatibility
Platform(s): Series 40, S60, Nokia Belle

Article
Keywords: java.util.TimeZone, java.util.TimeZone.getAvailableIDs, java.util.TimeZone.getRawOffset
Created: vltsoy (27 Nov 2008)
Last edited: hamishwillee (05 Oct 2012)

Contents

Overview

A list of all supported time zones is shown on the screen. By choosing a time zone from the list, the user can see the time offset it has. Method TimeZone.getTimeZone() allows the application to retrieve the chosen Time Zone and method TimeZone.getRawOffset() is used to retrieve the raw time offset for the chosen time zone.

Source file: ConvertingTimeZones.java

import java.util.TimeZone;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
 
public class ConvertingTimeZones extends MIDlet implements CommandListener {
 
private List list;
private Form form;
private Display display;
private TimeZone timeZone;
private Command backCommand;
private Command exitCommand;
 
/**
* Constructor. Constructs the object and initializes buffer.
*/

public ConvertingTimeZones() {
timeZone = TimeZone.getDefault();
backCommand = new Command("Back", Command.BACK, 1);
exitCommand = new Command("Exit", Command.EXIT, 0);
 
form = new Form("Time zone info");
form.addCommand(backCommand);
form.setCommandListener(this);
 
//Create list filled with all available time zone IDs.
list = new List("Select time zone:", List.IMPLICIT,
timeZone.getAvailableIDs(), null);
list.addCommand(exitCommand);
list.setCommandListener(this);
 
display = Display.getDisplay(this);
display.setCurrent(list);
}
 
/**
* From CommandListener.
* Called by the system to indicate that a command has been invoked on a
* particular displayable.
* @param cmd the command that was invoked
* @param displayable the displayable where the command was invoked
*/

public void commandAction(Command cmd, Displayable displayable) {
if (cmd == List.SELECT_COMMAND) {
//Clear form.
form.deleteAll();
//Get selected time zone index.
String timeZoneID = list.getString(list.getSelectedIndex());
form.append("Time zone ID: " + timeZoneID + "\n");
form.append("Time offset: ");
//Display the GMT offset for selected time zone in hours.
form.append(String.valueOf(
timeZone.getTimeZone(timeZoneID).getRawOffset() / 3600000));
form.append(" hours");
 
display.setCurrent(form);
} else if (cmd == backCommand) {
display.setCurrent(list);
} else if (cmd == exitCommand) {
notifyDestroyed();
}
}
 
/**
* From MIDlet.
* Called when the MIDlet is started.
*/

public void startApp() {
// No implementation required.
}
 
/**
* From MIDlet.
* Called to signal the MIDlet to enter the Paused state.
*/

public void pauseApp() {
// No implementation required.
}
 
/**
* From MIDlet.
* Called to signal the MIDlet to terminate.
* @param unconditional whether the MIDlet has to be unconditionally
* terminated
*/

public void destroyApp(boolean unconditional) {
}
}

Postconditions

This application allows the user to retrieve the time offset for any time zone he or she needs.

Supplementary material

The source file and executable application are available for download at Media:Converting time zones in J2ME.zip.

This page was last modified on 5 October 2012, at 09:30.
202 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved