This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date format" Watch "Date format" New topic
Author

Date format

Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 102

Hello,

I have this sql date 2009-05-11 00:00:00.0 in to my data base

String fecha = rs.getString("fecha")); // fecha is now 2009-05-11

java.text.SimpleDateFormat df= new SimpleDateFormat("dd-MM-yyyy");
java.util.Date d = df.parse(rs.getString("fecha"));
System.out.println(d); //shows Thu Oct 29 00:00:00 CET 16
It doesn't retieve the year , I also trying to convert with <fmt:formatDate value='${documento.dateFecha}' type="date" pattern="dd-MM-yyyy"/>
and i get 29-10-0016
I wnayt to get day- moth-year;
why i lost the year?

thanks
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3477
    
  13
Originally posted by Fernando Dominguez:

String fecha = rs.getString("fecha")); // fecha is now 2009-05-11

java.text.SimpleDateFormat df= new SimpleDateFormat("dd-MM-yyyy");


Look at the format of your string. Look at the pattern you are passing to SimpleDateFormat. It's not really surprising you are not getting the data you want.


Joanne
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Looks like "2009-05-11" will parse better with "yyyy-MM-dd". Let us know if that helps.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date format