Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange date format problem  RSS feed

 
Sharon Cowling
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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)
 
Irene Loos
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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 is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!