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

3
  • EST is UTC - 5 hours. America/New_York is EST in the winter and EDT in the summer, so right now New York is UTC - 4 hours.refer stackoverflow.com/questions/9863625/…
    – sasikumar
    Mar 3, 2016 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 3, 2016 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. Feb 11, 2018 at 22:20

0

Browse other questions tagged or ask your own question.