*
The moose likes Java in General and the fly likes DateFormat usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DateFormat usage " Watch "DateFormat usage " New topic
Author

DateFormat usage

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hello everyone,
Can some one tell me what do I need to add to this comand:
String date = DateFormat.getDateInstance().format(rs.getDate(1));
in order to get date in the form yyyy-mm-dd ?
P.S rs.getDate(1) returns date as yyyy-mm-dd hh:mm:ss.ms
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60804
    
  65

liliya, please take the time to choose the appropriate forum for your questions. This forum is for questions on JSP.

I've moved this topic to the Java in General (intermediate) forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41150
    
  45
getDate does not return the date in any particular format; maybe what you're seeing is what it prints if its toString method is invoked.

A simple way would be to remove everything from the space characters on, i.e. rs.getDate(1).substring(0,10).


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60804
    
  65

Check out the SimpleDateFormat class and apply an appropriate pattern.
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Thanks a lot to both of you.
Kevin Huang
Greenhorn

Joined: Mar 27, 2004
Posts: 13
If d is of type Date, then:

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(d);

upper case "MM".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DateFormat usage
 
Similar Threads
How to fetch Date Field from excel sheet in Java
Code review required for converting dateformat
why what i search is not what i want?
[log4j] DailyRollingFileAppender
date format