java - Parser Exception for format EEEE, MMMM d, YYYY h:mm:ss a z -


i'm getting parser exception on trying parse string value:

"thursday, july 27, 2006 10:10:02 pm pst"  

to format:

"eeee, mmmm d, yyyy h:mm:ss z" 

this program sample:

datetime.parse("thursday, july 27, 2006 10:10:02 pm pdt", datetimeformat.forpattern("eeee, mmmm d, yyyy h:mm:ss z")); 

and error message:

invalid format: "thursday, july 27, 2006 10:10:02 pm pdt" malformed @ "pdt" 

this sample program

string str = "thursday, july 27, 2006 10:10:02 pm pdt";  datetimeformatter formatterdatetime = datetimeformat.forpattern("eeee, mmmm d, yyyy h:mm:ss z"); try{     datetime dt = datetime.parse(str, formatterdatetime); }catch(exception ex) {     system.out.println(ex.getmessage()); } 

from jodatime docs:

zone names: time zone names ('z') cannot parsed.

however simpledateformat support parsing of timezones.

simpledateformat format = new simpledateformat("eeee, mmmm dd, yyyy h:mm:ss aa zzz"); date date = format.parse("thursday, july 27, 2006 10:10:02 pm pst"); 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -