There was a discussion on the list previously on formatting a date
object. It would be better to format the date at the business layer
rather than at the presentation layer. This is because if the view layer
is changed to use Swing or another web app framework, the date is
already formatted to the requirements of the application.

Amin

-----Original Message-----
From: Ripudaman.Sharma [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 17, 2003 9:02 PM
To: Struts Users Mailing List
Subject: RE: <bean:write property=""> Format a Date ?

Inspite of using substring.You can use SimpleDateFormat class which
provide
you the facility of format date to any any Date Format .For Your
refrence
sending code which is generic one and convert any DateFormat-

How to convert date from "2002-11-29" to "29/11/2002" (Or from any
format to
any format.
they can be passed as params.)


public static String convertDate(String date, String fromPattern, String
toPattern) {
    String newFormat = null;
    try {
        SimpleDateFormat fmt = new SimpleDateFormat(fromPattern);
        Date objDt = fmt.parse(date);
        fmt.applyPattern(toPattern);
        newFormat = fmt.format(objDt);
    }catch(ParseException pe)   {}
    return newFormat;
}


String newFormat = convertDate("2002-11-29", "yyyy-MM-dd",
"dd/MM/yyyy");
System.out.println(newFormat);    //will print 29/11/2002

Regard
Ripudaman Sharma
Analyst
Indus Software




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to