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

后端 未结 9 1454
后悔当初
后悔当初 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:20

    You can parse and format dates to and from any format using SimpleDateFormat

    0 讨论(0)
  • 2020-12-03 11:20

    Without knowing exactly what format you need, the generic response is: you're going to want DateFormat or SimpleDateFormat. There is a nice tutorial on both here.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题