• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting Date out with JSTL

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<fmt:formatDate type="both" dateStyle="default" timeStyle="default" value="${now}" />
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it, works now!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at formatDate as I suggested?
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic