Java Data Type How to - SimpleDateFormat format: Thu Jun 06 2013 00:00:00 GMT+0530








Question

We would like to know how to simpleDateFormat format: Thu Jun 06 2013 00:00:00 GMT+0530.

Answer

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/*from  ww  w  .  j  a v a  2  s.co  m*/
public class Main {
    public static void main(String[] args) {

        String str = "Thu Jun 06 2013 00:00:00 GMT+0530";
        DateFormat outputDate = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss");
        try {
             Date date = outputDate.parse(str);
             String date1 = new SimpleDateFormat("dd-mm-yyyy, hh:mm:ss").format(date);
             System.out.println(date1.toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}

The code above generates the following result.