I have been searching for a solution for a long time and haven't yet found a solution . I am getting a String from another page in JSP and before I need to parse it in a certain format of Date before I Store it into the DB (MySQL).
After this I get an Output of Wed Oct 31 00:00:00 IST 2012 where as I need the Date to be ("yyyy-MM-dd") format and also I want it to be a Date Object. Every time I convert a String into a format it adds Time , Day etc . And when I format it to a particular pattern then it converts it into a String . Can anyone help me ?
Varun Nambuthiri wrote:... I need the Date to be ("yyyy-MM-dd") format and also I want it to be a Date Object.
A Date doesn't have a format. You can apply a DateFormat to get a String from the Date, formatted the way you like it.
Have you read the API for Date?
The class Date represents a specific instant in time, with millisecond precision.
Darryl Burke worte :
I don't do JDBC, but can't you insert a date as a java.sql.Date? (and wouldn't that be a more correct approach?)
Well that would be the Case but Then also the conversion of anything into a Date object will lead to appending of the extra information like Day , Time , Time Zone . I dont want that . Well thats not a problem anymore since I was able to insert a String date of that format .