1

I have implemented the below code in my app to display the date and time with timezone.

    Date d = new Date();
    SimpleDateFormat sdformat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a z");
    sdformat.setTimeZone(TimeZone.getTimeZone("EST"));
    System.out.println(sdformat.format(d));

If I run the above code in eclipse, I get the output as:

11/13/2015 07:23:56 PM EST

But for the same code in android device, I get the output as:

11/13/2015 07:23:56 PM GMT-5.00

Why is the difference, I need the date format to be displayed as:

11/13/2015 07:23:56 PM EST

walkmn
  • 2,322
  • 22
  • 29
sarath19
  • 198
  • 1
  • 11

1 Answers1

1

TimeZone.getTimeZone(String id) is designed to use so-called Olson format among others as a parameter. Details you can find here.

EST time corresponds to the value "America/New_York", so

sdformat.setTimeZone(TimeZone.getTimeZone("America/New_York")); 

will give the expected result.

DmitryArc
  • 4,757
  • 2
  • 37
  • 42