• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get required date format from resultset......  RSS feed

 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Added code tags - see UseCodeTags for details]

I want ot get date format like "dd-mm-yy".The above code not giving correct output
can anyone please help me...........
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is a class in java for it , SimpleDateFormatter . You will get plenty of code online for it

Regards,
Vishal
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Date.getMonth(), getYear() methods etc are all deprecated (because they don't cope with time zones etc very well). But Vishal is right - using SimpleDateFormat is the easiest way to output Dates in the way you want.
 
Winston Gutkowski
Bartender
Posts: 10574
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
narayana Ega wrote:I want ot get date format like "dd-mm-yy".The above code not giving correct output

And further to the other good advice: Are you sure you want that?

Your code would appear to be loading some sort of spreadsheet, in which case couldn't you just load it as a date? If it's something like Apache POI, then the display format should probably be specified by the cell format (if you can do that with POI), not by converting the date to a String.

Winston
 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to set cell date format in POI......
 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to set cell date format in POI......
 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CreationHelper createHelper = workbook.getCreationHelper();
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yy"));

cell.setCellValue(res.getString("mdate"));
cell.setCellStyle(cellStyle);

Eventhough i set like this its coming like 01-01-1970 05:30:00.....what i have to do reply me......
 
Winston Gutkowski
Bartender
Posts: 10574
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
narayana Ega wrote:Eventhough i set like this its coming like 01-01-1970 05:30:00.....what i have to do reply me......

I'm no POI expert, but it's probably because you're setting it from a String. Doesn't POI have a way of setting values from a Java Date? Because that's what it is.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!