Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / September 2003

Tip: Looking for answers? Try searching our database.

JSP date manipulation (newbie)

Thread view: 
Tom - 24 Sep 2003 10:46 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
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.