Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i want to convert string date to date format for storing database table.The below code is not working.it showing java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date Exception.

Date date = (Date)hmap.get("skillexpdate");

share|improve this question
add comment

2 Answers

Use SimpleDateFormat#parse() instead; you cannot directly cast a String instance into a Date.

share|improve this answer
add comment

You can't simply cast. You need to use SimpleDateFormat.parse() to convert String to Date.

share|improve this answer
 
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date date=formatter.parse(hmap.get("skillexpdate").toString()); i changed the code above format still it is showing same exception.. –  Ajithlal Nov 8 '13 at 21:52
 
@Ajithlal: Parameter format changes based on what format your String is. For example if String is in format 2013-09-27, then your code in above comment will work fine. –  Nambari Nov 8 '13 at 21:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.