Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert java.util.Calendar in JSTL?

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all:
On my jsp, i got a collection and loops through it,

something like this


Thank you so much for your kindness help.
Regards.
[ January 08, 2007: Message edited by: Bear Bibeault ]
 
Hung Tang
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jay lai:
Hi all:
On my jsp, i got a collection and loops through it,

something like this


Thank you so much for your kindness help.
Regards.

Look into <fmt:formatDate> and <fmt:parseDate>

[ January 06, 2007: Message edited by: Hung Tang ]
[ January 08, 2007: Message edited by: Bear Bibeault ]
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please elaborate more on what exactly I have to do, to convert the java.util.Calendar using <fmt:formatDate>, I tried it but it seems not work.


I guess I have to convert the java.util.Calendar to java.util.Date on the jsp? using <fn:parseDate> ..but not quite sure how to do it.

Thank you in advance if any hints or help
Really appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you passing a Calendar object to the JSP in the first place? It's a computational class, not a display class. Convert the Calendar to a Date before you send it to the JSP.

Remember, whenever you find something that's hard to do in the JSTL or EL, it's a red flag that you're probably doing something wrong.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
This question is follow-up with the previouse post. I recevied the class that have the getter/setting as java.util.Calendar in the array type. So if I want to convert one field with java.util.Calendar to java.util.Date and add it back to the array, and return the whole array back to JSP, how do I do it..

[code]
public class School implements Serializable
protected java.util.Calendar startTime; have getter/setter
protected String location;

In another class I invoke this class

School[] = null;
School = someObj.getSchoolArray(); // it works fine at this point and return the School array back to jsp with the startTime in java.util.Calendar format.

From here, i want to convert startTime from the School[] that I get to java.util.Date

for (int i =0; i<School.length; i++)
{
Date startDate = new Date()
startDate.setTime(School[i].getStartTime.getTimeInMillis());
// here I want to add this new startDate back to the array School[], how do I do it. ?
}

Many thanks in advance and always greatly appreciated with your help.
Regards
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please disregard the previouse post, since I don't want to repost another topic . This is kind of interelated with the "subject topic"

Okey, I got a java.util.Date with this format Jan 10, 2007 12:01:03 PM
I want to just display the whole 12:01:03 into second on the jsp.
How do I do this using JSTL tag lib

<fmt:formatDate>
<fmt:parseDate> // how do I utilize these tag. Thanks

Respectedly thanks to all your help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a java.util.Date handy, there's no need for the parseDate action; formateDate is all you need.

With regards to using <fmt:formatDate> the JSTL Specification has all the info you need.

If you are writing JSP pages with JSTL without a copy of the JSTL Spec, you are doing it wrong. Links to the various specifications can be found in the JSP FAQ.
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>>Remember, whenever you find something that's hard to do in the JSTL or EL, it's a red flag that you're probably doing something wrong.
Ok I agree. I have a Calendar object and I just want to display the full year , month and the date in the front end.
I extract the date from the calendar and you are telling me to use those deprecated methods of the Date in my JSP to get the full year , month and the date
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anoop Krishnan wrote:I have a Calendar object and I just want to display the full year , month and the date in the front end.
I extract the date from the calendar and you are telling me to use those deprecated methods of the Date in my JSP to get the full year , month and the date


I didn't see any such advice. Can you quote something from the thread which says that?

However I did see advice to use <fmt:formatDate>... perhaps you could review the thread and see if you could find that too.
 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Why are you passing a Calendar object to the JSP in the first place? It's a computational class, not a display class. Convert the Calendar to a Date before you send it to the JSP.

Remember, whenever you find something that's hard to do in the JSTL or EL, it's a red flag that you're probably doing something wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic