I wanted to convert from string to java.util.Date. For the same purpose, I used the following code,
String timeStamp = "Mon Feb 14 18:15:39 IST 2011";
DateFormat formatter = new SimpleDateFormat("dow mon dd hh:mm:ss zzz yyyy");
Date ts = (Date)formatter.parse(timeStamp);
The format given by SimpleDateFormat () is the java.util.Date format. When you convert util Date to a string, it comes in this format ('dow mon dd hh: mm: ss zzz yyyy'). But when I execute the code, it gives me an exception. I don’t know what exactly I needed to do to get rid of this problem. I am sending a StackTrace exception part. If anyone knows a solution,
java.lang.IllegalArgumentException: Invalid template character 'o' at java.text.SimpleDateFormat.compile (SimpleDateFormat.java:769) in java.text.SimpleDateFormat.initialize (SimpleDateFormat.java∗76) in java.text.SimpleDateForm. (SimpleDateFormat.java//01) in java.text.SimpleDateFormat. (SimpleDateFormat.java-00-0076) Thank you in advance.
Sagar source
share