1

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.

Coder Guru
  • 513
  • 3
  • 18
  • 37

1 Answers1

4

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());
Kushan
  • 10,657
  • 4
  • 37
  • 41
  • Kushan,getting error like java.lang.IllegalArgumentException java.sql.Date.valueOf(Date.java:138) I am using code like this java.sql.Date postsqlDate = java.sql.Date.valueOf(dt); and dt is like this-Tue Jan 17 22:35:00 IST 2012 – Coder Guru Jan 23 '12 at 06:13
  • Kushan i am getting null in place of updated date from rome...So at the time of the insertion it fire exception as nullpointer exception.For this reason i added today=fmt.parse("0000-00-00 00:00:00"); as a default date but it fires exception as Unparseable date..What i should keep the default date. – Coder Guru Jan 23 '12 at 07:15