Convert Java Date into XML Date Format (and vice versa)

后端 未结 9 1650
后悔当初
后悔当初 2020-12-03 10:46

Is there a nice and easy way to convert a Java Date into XML date string format and vice versa?

Cheers,

Andez

9条回答
  •  长情又很酷
    2020-12-03 11:21

    Using Joda Time you would do the following:

    DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); // ISO8601 (XML) Date/time
    DateTime dt = fmt.parseDateTime("2000-01-01T12:00:00+100"); // +1hr time zone
    System.out.println(fmt.print(dt)); // Prints in ISO8601 format
    

    Thread safe, immutable and simple.

提交回复
热议问题