• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...........
 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to set cell date format in POI......
 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to set cell date format in POI......
 
narayana Ega
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic