ISO8601DateConverter without milliseconds

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ISO8601DateConverter without milliseconds

bhuffman
All,

Is there any way to use the ISO8601DateConverter without milliseconds?  
Right now, whenever I call xstream.toXML(object), I'm getting
milliseconds in the output.

This is how I'm specifying the converter:
     static {
         xstream.registerConverter(new ISO8601DateConverter());
     }

Thanks,
Brian



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: ISO8601DateConverter without milliseconds

Jörg Schaible-2
Hi Brian,

Brian C. Huffman wrote:

> All,
>
> Is there any way to use the ISO8601DateConverter without milliseconds?
> Right now, whenever I call xstream.toXML(object), I'm getting
> milliseconds in the output.
>
> This is how I'm specifying the converter:
>      static {
>          xstream.registerConverter(new ISO8601DateConverter());
>      }

XStream's converter will always convert into a String with maximal
information, but you can easily overwrite the toString method using a
different formatter of Joda-Time:

  xstream.registerConverter(new ISO8601DateConverter() {
    String toString(Object o) {
      return new DateTime(o).toString(ISODateTimeFormat.dateTimeNoMillis());
    }
  });

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email