how to parse the following date format Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time) in java

I am getting the date in the format Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time). I have to convert it to sql date of format dd/MM/yyyy. Please help.

I tried below code but did not help

Date date = new java.sql.Date(
(new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zz (zzzz)").parse("Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time)"))
.getTime());

Answer

Something like below, also refer here for Java SimpleDateFormat

public static void main(String[] args) throws ParseException {
        String time = "Mon Nov 09 2015 00:00:00 GMT+0530 (India Standard Time)";
        DateFormat inputFormat = new SimpleDateFormat(
                "E MMM dd yyyy HH:mm:ss 'GMT'z", Locale.ENGLISH);
        Date date = inputFormat.parse(time);
        System.out.println(date);

        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
        System.out.println(formatter.format(date));
    }

output

Mon Nov 09 00:00:00 IST 2015
09/11/2015

Leave a Reply

Your email address will not be published. Required fields are marked *