0

Performing some operations using Java Date. Have the following code

public static void main(String[] args) {

        String dateFormat="yyyy-MM-dd HH:mm:ss.SSS";
        String d="1970-04-10 00:00:00.0";
        Date parsingDate=null;
        XMLGregorianCalendar xl=null;

        SimpleDateFormat parser = new SimpleDateFormat(dateFormat);
        parser.setTimeZone(TimeZone.getTimeZone("America/New_York"));
        try {
            parsingDate=parser.parse(d);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.println(parsingDate);
    }

The output is Fri Apr 10 10:30:00 IST 1970.

Shouldn't this not be IST and be EST as follows Fri Apr 10 10:30:00 EST 1970.

Thanks

Rehan
  • 929
  • 1
  • 12
  • 29
  • EST is UTC - 5 hours. America/New_York is EST in the winter and E*D*T in the summer, so right now New York is UTC - 4 hours.refer http://stackoverflow.com/questions/9863625/difference-between-est-and-america-new-york-time-zones – sasikumar Mar 03 '16 at 10:11
  • When I ran your code, I had CET. Because Date does not have the notion of timezone. CET is my system timezone, which is what `toString()` uses. – Tunaki Mar 03 '16 at 10:14
  • FYI: Using *java.time* classes… `LocalDate.parse( "1970-04-10" ).atStartOfDay( ZoneId.of( "America/New_York" ) ).toString()` ➤ `1970-04-10T00:00-05:00[America/New_York]`. Search *Stack Overflow* for those classes to learn more. – Basil Bourque Feb 11 '18 at 22:20

0 Answers0