commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Benedict <pbened...@apache.org>
Subject Re: [betwixt] Writing Calendar
Date Tue, 03 Aug 2010 18:11:25 GMT
Call getTime() to transform Calendar to Date, and then use SimpleDateFormat
to transform into a string.

On Tue, Aug 3, 2010 at 1:03 PM, Rik Scarborough <riksca@gmail.com> wrote:

> How do you write out a Calendar as a String, such as 1993-12-01T00:00:00Z
>
> I've added a ObjectStringConverter that will convert a Date, but it seems
> to
> ignore the Calendar.
>
>        public String objectToString(Object object, Class type, Context
> context) {
>            if(object != null) {
>                if(object instanceof java.util.Date) {
>                    return formatter.format((java.util.Date) object);
>                } else if (object instanceof java.util.Calendar) {
>                    logger.info("Class type " + type.getName());  //<<
> never
> gets printed.
>                    return formatter.format(((java.util.Calendar)
> object).getTime());
>                }
>            }
>            return super.objectToString(object, type, context);
>        }
>
> I need the same result for Calendar as Date would print out.  Any
> suggestions?
>
> ~Rik
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message