You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mick Knutson <mi...@hotmail.com> on 2003/05/30 10:08:57 UTC

DateUtilities for ActionForms?

Is there already a set of DateUtilities for ActionForms?
I am finding myself converting to and from Strings and also reformating my 
Dates to and from my DB.

I am using EntityBeans and ValueObjects with my ActionForms, so to keep the 
types in synch, it seems I have to do serious conversion all the time.
Thanks in advance for the help.

---
Thanks...
Mick Knutson
---

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: DateUtilities for ActionForms?

Posted by Gareth Andrew <ga...@ntlworld.com>.
Mick,

Have you tried using the BeanUtils converters. 
 From the docs:

*org.apache.commons.beanutils.locale.converters.DateLocaleConverter
*
Standard |LocaleConverter| <ci...@ntlworld.com> 
implementation that converts an incoming locale-sensitive String into a 
|java.util.Date| object, optionally using a default value or throwing a 
|ConversionException| <ci...@ntlworld.com> if a 
conversion error occurs.

It sounds like it might help, but I haven't used it before so i can't 
comment.  At the very least the source might be useful if you decide you 
need to write your own DateUtilities.

HTH.

Gareth.

Mick Knutson wrote:

> Is there already a set of DateUtilities for ActionForms?
> I am finding myself converting to and from Strings and also 
> reformating my Dates to and from my DB.
>
> I am using EntityBeans and ValueObjects with my ActionForms, so to 
> keep the types in synch, it seems I have to do serious conversion all 
> the time.
> Thanks in advance for the help.
>
> ---
> Thanks...
> Mick Knutson
> ---
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: DateUtilities for ActionForms?

Posted by Mark Galbreath <ma...@qat.com>.
I wrote a simple conversion method and pass the Strings through - no hassle
at all. Given the String "Jan 1, 2003":

Calendar date = getDate( string );

private Calendar getDate( String string ) {
  Calender cal = Calender.getInstance();
  String formatted_date = null;
  String[] months = {
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
  StringTokenizer st = new StringTokenizer( string );
  String str = st.nextToken();

  for( int i; i < months.length; i++ ) {

    if( str.equalsIgnoreCase( months[ i ] )) {
      month = i;
      break;
    }
  }

  String temp = st.nextToken();
  StringTokenizer token = new StringTokenizer( temp, "," );
  date = ( new Integer(( String ) token.nextElement() )).intValue();
  year = ( new Integer(( String ) st.nextElement() )).intValue();

  return( cal.set( year, month + 1, date ));
}


Easy, heh?  You could also use regular expressions if you are using JDK 1.4.

Mark

-----Original Message-----
From: Mick Knutson [mailto:mickknutson@hotmail.com] 
Sent: Friday, May 30, 2003 4:09 AM
To: struts-user@jakarta.apache.org
Subject: DateUtilities for ActionForms?


Is there already a set of DateUtilities for ActionForms?
I am finding myself converting to and from Strings and also reformating my 
Dates to and from my DB.

I am using EntityBeans and ValueObjects with my ActionForms, so to keep the 
types in synch, it seems I have to do serious conversion all the time.
Thanks in advance for the help.

---
Thanks...
Mick Knutson
---

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org