my dog learned polymorphism*
The moose likes JSP and the fly likes How to convert java.util.Calendar in JSTL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to convert java.util.Calendar in JSTL?" Watch "How to convert java.util.Calendar in JSTL?" New topic
Author

How to convert java.util.Calendar in JSTL?

jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
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

Joined: Feb 14, 2002
Posts: 148
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

Joined: Apr 04, 2002
Posts: 180
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

Joined: Jan 10, 2002
Posts: 61198
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
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

Joined: Apr 04, 2002
Posts: 180
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

Joined: Jan 10, 2002
Posts: 61198
    
  66

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

Joined: May 03, 2001
Posts: 163
>>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


I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 03, 2001
Posts: 163
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert java.util.Calendar in JSTL?