• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Problem with parsing Date  RSS feed

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

 
Varun Nambuthiri
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!