struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ripudaman.Sharma" <>
Subject RE: <bean:write property=""> Format a Date ?
Date Wed, 17 Sep 2003 13:02:02 GMT
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);
        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

Ripudaman Sharma
Indus Software

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message