File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem with parsing Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with parsing Date" Watch "Problem with parsing Date" New topic
Author

Problem with parsing Date

Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Hi,

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).
I have


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 ?

Regards
Varun


All's well that Debugs well .
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4640
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Hi !

Thanks for the reply Darryl ! I was able to solve it . Actually I didnt know that I could just insert the date as a String and be done with it as the MySQL just converts it into the neccessary format.

Regards
Varun
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4640
    
    5

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?)
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Thanks Darryl for the reply .

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 .

Regards
Varun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with parsing Date