Java String to Date unparsable date -


this string i'm extracting info using regex:

2823893a2f91c7507831f140dd7aa75e420477b0 - #0023922: fixed message defaulted bonds ; thu oct 25 12:08:25 2012 +0000

this code use extract string , try make date:

pattern pattern3 = pattern.compile(";\\s(.*)"); matcher matcher3 = pattern3.matcher(s); matcher3.find(); string t = matcher3.group(1).tostring();        try {          date time = new simpledateformat("dd/mmm/yy hh:mm a").parse(t);        } catch (parseexception e) {               e.printstacktrace();        } 

this should format of input:

thu oct 25 12:08:25 2012 +0000 

and want make date aforementioned string looks like:

25/oct/12 12:08 pm 

but keep getting these errors:

java.text.parseexception: unparseable date: "thu oct 25 12:08:25 2012 +0000" fixed message defaulted bonds0null     @ java.text.dateformat.parse(dateformat.java:337)     @ gititem.cultivategititem(gititem.java:42)     @ main.main(main.java:9) java.text.parseexception: unparseable date: "thu oct 25 11:52:39 2012 +0000"     @ java.text.dateformat.parse(dateformat.java:337)     @ gititem.cultivategititem(gititem.java:42)     @ main.main(main.java:9) 

i remove unwanted part:

string dateasstring = s.replaceall(".*;\\s+",""); 

then need dateformat: 1 parse string , 1 output correct format:

string s = "2823893a2f91c7507831f140dd7aa75e420477b0 - #0023922: fixed message defaulted bonds ; thu oct 25 12:08:25 2012 +0000"; system.out.println("s = " + s); string dateasstring = s.replaceall(".*;\\s+",""); system.out.println("dateasstring = " + dateasstring); dateformat parser = new simpledateformat("eee mmm dd hh:mm:ss yyyy x", locale.english); date date = parser.parse(dateasstring); system.out.println("date = " + date); dateformat formatter = new simpledateformat("dd/mmm/yyyy hh:mm a", locale.english); formatter.settimezone(timezone.gettimezone("utc")); system.out.println(formatter.format(date)); 

outputs:

s = 2823893a2f91c7507831f140dd7aa75e420477b0 - #0023922: fixed message defaulted bonds ; thu oct 25 12:08:25 2012 +0000 dateasstring = thu oct 25 12:08:25 2012 +0000 date = thu oct 25 14:08:25 cest 2012 25/oct/2012 12:08 pm 

note: need use appropriate locale parse , print month/day names


Comments