-1

Below code is throwing an exception while parsing the date.

DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
String timestamp = "20131113-210429";
String suffix;
try {
     suffix = df.format(timestamp);
}

Where can i get the list of permissible date formats?

user170008
  • 1,046
  • 6
  • 17
  • 31
  • 3
    Don't you want to do parse()? – kosa Nov 13 '13 at 21:20
  • *where can I get the list of permissible date formats*: in the javadoc of the class you're using: SimpleDateFormat, or course: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html – JB Nizet Nov 13 '13 at 21:21

2 Answers2

3

Your hour should be HH for 24 hours format, current it is hh which is for 12 hours format.

So your format should be: "yyyyMMdd-HHmmss"

Habib
  • 219,104
  • 29
  • 407
  • 436
  • am getting the same error when changed to the "yyyyMMdd-HHmmss" – user170008 Nov 13 '13 at 21:23
  • @user170008, you need to parse the string to Date using this format, you can't format a string using `SimpleDateFormat`. See this question for how to do parsing http://stackoverflow.com/questions/9872419/converting-string-to-date-using-simpledateformat – Habib Nov 13 '13 at 21:24
2

Java API docs are always your friend.

codesalsa
  • 882
  • 5
  • 18