jQuery in Action, 2nd edition
The moose likes JSP and the fly likes Formatting date in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Formatting date in JSP" Watch "Formatting date in JSP" New topic
Author

Formatting date in JSP

Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
When I use ${person.birthday} directly, it shows up as

"Wed Jun 11 00:00:00 EDT 1975"

How can I format it to something like "June 11, 1975"? By using an EL function call?

Thanks in advance!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

You can't do it using an EL function (unless you write your own). But there's no need since the <fmt:formatDate> action of the JSTL does it for you.

Any reason that you need to use an EL function as opposed to the JSTL?
[ April 09, 2007: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
ah ok, thanks.

I'll just use <fmt:formatDate>.
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Related question:

I have a height value that's in inches. How can I format it so it's in feet and inches?

I tried the codes below but it gives 1 extra foot.

Example:
67 inches should be 5' 7"
but the code below gives 6' 7"

[ April 11, 2007: Message edited by: Wilson Gordon ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

It's rounding up due to the fractional digit setting. If you put in 65 inches, you get the expected result.

For the feet calculation, you'll need to do bit more math to subtract out the fractional part. Or you could write an EL function that does truncating division for you.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You could also subtract a foot if the modulus isn't zero.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

Or do this to negate the rounding-up tendency:
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Thanks for the replies!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting date in JSP
 
Similar Threads
Stucked in group by !!
Formating a Date
SEVERE: BAD packet signature 200,SEVERE: Caught exception (java.lang.NullPointerException)
complemet value for -128
time comparison between given periods