This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes getting Date out with JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "getting Date out with JSTL" Watch "getting Date out with JSTL" New topic
Author

getting Date out with JSTL

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I'd like to be able to check via JSTL fmt library the time of the day, (say if it is 2 pm or not) and attach html tags based on output of the test. For some reason I'm not getting any errors or the date out when I do the following:

Could someone tell me please what I'm missing from the above?...I do import the fmt library.
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
<fmt:formatDate type="both" dateStyle="default" timeStyle="default" value="${now}" />
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
I'm still not getting anything out. I declare var now as follows:

and I access it (as suggested above), but no date is shown. Since I need time of the date, maybe there is a way of getting just the time?
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
got it, works now!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61318
    
  66

Originally posted by liliya woland:
maybe there is a way of getting just the time?


If now is a Date, why are you messing around with parseDate?

You have a copy of the JSTL Spec handy, right? Look up formatDate and see what it has that can help you.

Hint: also look up java.text.DateFormat


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
So I did clean up the jstl code and now I do get the time only. I'm doing this to test if it is 2pm. I'd like to be able to do this using jstl notation, although writing a scriplet will probably be faster.
I'd like to have a test that would do something as below, but don't know if this is at all possible via jstl.

Thank you in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61318
    
  66

Did you look at formatDate as I suggested?
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Yes, I got the time out of it with

I actually found my old java code for getting all the info I need (hour,ampm), so I think I'm going with a scriptlet and plain java code - takes much less time.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61318
    
  66

Originally posted by liliya woland:
so I think I'm going with a scriptlet and plain java code - takes much less time.


Not the best of attitudes.

Here's the way:



The secret is in knowing how to use the pattern attribute.
[ April 18, 2007: Message edited by: Bear Bibeault ]
 
GeeCON Prague 2014
 
subject: getting Date out with JSTL