Hi
I am storing a date in a mySQL db in the format 2003-01-01
I have a bean that I use to extract the info from the db but am wondering if
it is possible to manipulate the date into something like 1 Jan 2003 in JSP?
Thanks for any advice
T
Steve Heath - 24 Sep 2003 11:33 GMT
> Hi
> I am storing a date in a mySQL db in the format 2003-01-01
> I have a bean that I use to extract the info from the db but am wondering if
> it is possible to manipulate the date into something like 1 Jan 2003 in JSP?
> Thanks for any advice
> T
if you're willing to use taglibs
http://java.sun.com/products/jsp/jstl/
have a look at the format stuff in the reference:
http://www.manning.com/bayern/appendixA.pdf
from page 16 (section A5. Formatting)
but specifically page 18 (section A.5.2. Dates)
Might be preferable to encapsulate your date-format
(java.text.SimpleDateFormat) in the bean with a separate function so
that you can be sure your website has the same formate everywhere, but I
don't know enough about what you're doing to say for definite.
steve
Iain Downie - 26 Sep 2003 10:51 GMT
> Hi
> I am storing a date in a mySQL db in the format 2003-01-01
> I have a bean that I use to extract the info from the db but am wondering if
> it is possible to manipulate the date into something like 1 Jan 2003 in JSP?
If you can get the date from the database into a Calendar object you can set
up the date format with
<%
java.text.SimpleDateFormat dateForm=new java.text.SimpleDateFormat("EEE, d
MMM, yyyy");
%>
Then use
<%=
dateForm.format(observationDate.getTime())
%>
Which should return 'Thu, 21 Apr, 1994'. You can play with the EEE, d MMM,
yyyy bit to get the desired format.
HTH
Iain