Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Strange date format problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JSP page which runs a query, stores the results in a Vector, and then spits them out in a specific order on the page, my problem is that the date comes out of the database in the format of: yy-MM-dd and I want dd-MM-yy, so using SimpleDateFormat I have included this in my code, but instead of my format I get a different format which shows completely incorrect dates:
<code snippet>
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyy");

while (!rs.isAfterLast()){
for (int i = 1; i< numberOfColumns; i++) {
tmpString = rs.getString(i);
if (tmpString.equals(rs.getString("date_from"))){
d1 = sdf.parse(tmpString);
tmpString = d1.toString();
}
if (tmpString.equals(rs.getString("date_to"))){
d2 = sdf.parse(tmpString);
tmpString = d2.toString();
}

tmpVector.add(tmpString);
}
rs.next();
}
</code snippet>
Output:
Permit 1
1018
Katrina
Cowling
Lake Taupo
Fri Feb 19 23:00:00 GMT+12:00 0006
Fri Feb 19 23:00:00 GMT+12:00 0006
Permit 2
1018
Katrina
Cowling
Lake Taupo
Fri Feb 19 23:00:00 GMT+12:00 0006
Fri Feb 19 23:00:00 GMT+12:00 0006
...and so on.
Any ideas? (February the 19th was not a Friday)
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sharon,
We are using it this way:
<code snippet>
String string;
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yy");
string = dateFormat.format(tmpString);
</code snippet>
Try it.
Irene
 
It's just a flesh wound! Or a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic