developers

    Forum Stats

  • 3,874,067 Users
  • 2,266,672 Discussions
  • 7,911,721 Comments

Discussions

Get Java ME to print PST instead of GMT.

bjuntti
bjuntti Member Posts: 14
edited Nov 11, 2014 8:38AM in Java ME Embedded

I can get Java SE to print local TZ (PST) but I can't seem to get the same code to work on Java ME embedded.  Here's the code: (be gentle - I'm a Java neophyte :-) )

import java.util.TimeZone;

import java.util.Date;

import java.util.Calendar;

public class TZTest {

    public static void main(String args[]) {

        TimeZone tz = Calendar.getInstance().getTimeZone();

        Calendar now = Calendar.getInstance();

        now.setTimeZone(tz);

        System.out.println("Time and date: " + now.getTime());

    }

}

When I run that code in a midlet with Java ME (minus the 'main' of course) I get:

Starting emulator in execution mode

Time and date: Fri Nov 07 14:35:38 GMT-08:00 2014

The same thing happens using my Raspberry Pi as EmbeddedExternalDevice.  I tried it under Linux Ubuntu, and it prints out as PST.  What is going on?

How do I get PST?

Thanks for any help.  It's driving me bonkers.

Answers

  • Hi!

    This likely comes from the fact that the only time zone Java ME is required to support is GMT (Check JSR-360 spec, TimeZone class). So despite of your device OS timezone Java ME uses GMT. Indeed it's not prohibited to support other time zones, but Java ME port to RPi does not have such support, sorry. This might be added in the future versions depending on necessity

    Andrey

This discussion has been closed.
developers