This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
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...........
 
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
 
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.
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE 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: 10777
71
Hibernate Eclipse IDE 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
 
I like tacos! And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!