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

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

    To comply with ISO8601, the timezone must be in the format +HH:MM or - HH:MM

    With Simpledateformat you must use XXX instead of Z (see NovelGuy answer)

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    

提交回复
热议问题