Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Date Problem

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I use MySql as database and I need to retrieve a date field (in yyyy-mm-dd format) and show it in dd-mm-yyyy format as a String.Is it possible? Can anybody help please?
Codes will be welcome.
Thanks.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that you obtain the date from mySQL through a resultSet i.e. resultset.getDate(int), the java.util.Date object returned (date) can be parsed like so:
SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance();
format.applyPattern("dd-MM-yyyy");
String formattedDate = format.format(date);
You can perform this piece of code in your responding servlet or through a JSP taglib that takes in the java.util.Date as an argument in the JSP and performs the logic in its tag class.
For a decent datetime JSP taglib see: http://jakarta.apache.org/taglibs/doc/datetime-doc/intro.html
Alternatively you can easily write one yourself.
AO.

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get the answer in this thread.. It worked fine..
http://www.javaranch.com/ubb/Forum50/HTML/000351.html
Pranit..

Originally posted by barnali chakrabarty:
Hi:
I use MySql as database and I need to retrieve a date field (in yyyy-mm-dd format) and show it in dd-mm-yyyy format as a String.Is it possible? Can anybody help please?
Codes will be welcome.
Thanks.


 
Anderson gave himself the promotion. So I gave myself this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic