Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DateFormat usage  RSS feed

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the SimpleDateFormat class and apply an appropriate pattern.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to both of you.
 
Kevin Huang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If d is of type Date, then:

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

upper case "MM".
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!