How to convert rome date format "Sun Jan 08 02:25:00 IST 2012" date to sql date

3.1k views Asked by At

I am using rome 0.9 for getting rss feeds.but from that getting blog post's date
as in the format "Sun Jan 08 02:25:00 IST 2012" .

I am unable to convert this date format to the sql date format.Actually i want to sort the blog posts according to the post date.

How to parse the date.

1

There are 1 answers

2
Kushan On BEST ANSWER

try this way,

String str_date  = "Sun Jan 08 02:25:00 IST 2012";
    SimpleDateFormat fmt = new SimpleDateFormat("E MMM dd hh:mm:ss Z yyyy");
    Date today = null;
    try {
        today = (Date)fmt.parse(str_date);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  

    java.sql.Date dt = new java.sql.Date(today.getTime());
    System.out.println(dt.toString());