This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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: 3432
    
  12
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
 
Similar Threads
How to change Date Format
date format conversion to MM/dd/yyyy hh:mm a
doubt on exp date 11/10/2009
How do i format a string to date
issue with datetimepicker & autocompleter in struts 2