0

I am in US-Central time and trying to store below date in EST but it is giving me a wrong output:

String reportedDate = "06-14-2016 02:10:59 PM";

below is my output:

TimeZone:Eastern Standard Time
Zone:America/New_York
Date:06-14-2016 03:10:59 PM

I used below code:

SimpleDateFormat sdfInCentral = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a");   
String reportedDate = "06-14-2016 02:10:59 PM";    
Date birthDate = sdfInCentral.parse(reportedDate);   
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("America/New_York")));   
TimeZone tz = TimeZone.getDefault();   
sdfInCentral.setTimeZone(tz);     
Rani
  • 13
  • 6

1 Answers1

0

From the mentioned information you can try something like this

    SimpleDateFormat sdfInCentral= new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a");
    sdfInCentral.setTimeZone(TimeZone.getTimeZone("EST"));
    String reportedDate = "06-14-2016 02:10:59 PM";    
    Date date = sdfInCentral.parse(reportedDate);
    System.out.println(date); 
Shersha Fn
  • 1,511
  • 3
  • 26
  • 34
  • 1
    I don't see how this answers the original question. Also, you should be using `America/New_York`, not `EST`. Daylight saving is in effect on this date, which is not reflected by setting the time zone to `EST`. See [this question](http://stackoverflow.com/q/9863625/634824) – Matt Johnson-Pint Jun 15 '16 at 03:53
  • +100 to Matt Johnson, never use three letter timezone abbreviations – Affe Apr 26 '17 at 19:32