Hi Chris,

Thanks, for the help.

I changed the my code

Date parsed = format.parse(date_);
     return format.format(parsed);

And this works fine for me.

I looked at the format tag for <bean:write>  but I use 
<c:out value="${orderDetailForm.ordersMasterListData.orderDate}"/>

And I can not get this to work with <bean:write>  tag.

I know there is a <%@ taglib uri="http://java.sun.com/jstl/fmt"; prefix="fmt"
%> but I did not use it yet will probably look at it later for more options
to do this in future.

Kr
Neil Meyer

-----Original Message-----
From: Christopher Schultz [mailto:[EMAIL PROTECTED] 
Sent: 07 March 2007 07:24 PM
To: Struts Users Mailing List
Subject: Re: Struts Date Formatting

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Neil,

Neil Meyer wrote:
> Code used.
> 
> String date_ = "2007-03-07 00:00:00"
> SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy");
> return formatter.format(date_); 

SimpleDateFormat.format() is expecting a java.util.Date argument, not a
String. If you want to convert a String to a Date, you need to use
SimpleDateFormat.parse(), which accepts a String argument and returns a
java.util.Date object.

> Date now = new Date();
>         // Print the result of toString()
> String dateString = now.toString();
>         System.out.println(" 1. " + dateString);
> 
> SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
> 
>        try {
>             Date parsed = format.parse(dateString);

dateString doesn't match your format. According to the Javadoc,
java.util.Date.toString dumps a string in the format "dow mon dd
hh:mm:ss zzz yyyy", which, unfortunately for you, uses localized names
for the day of the week and the month. If you want to parse strings
coming from Date.toString, you'll need to adjust your format when you
create SimpleDateFormat to match what you're trying to parse.

> Any help either the struts formatting or the way to fix it will really be
> appreciated.

Another poster suggested using <bean:write> with the "format" argument,
which can be used to format java.util.Date objects in whatever way you
choose.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF7vU59CaO5/Lv0PARAlnRAJ9lQajsAi/4N+9//U+S+Fe+zq5KBQCcDQR/
5e2IaMgf1CCjWbtIcAskVBU=
=qzCU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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