0

I'm trying to convert the following XMLSchema datetime datatype literal

   "~@http://www.w3.org/2001/XMLSchema#dateTime 2015-04-18T07:52:53.653"

into Java datetime object. I tried different alternatives including the one presented in Java SimpleDateFormat pattern for W3C XML dates with timezone, but never succeeded. Also tried the issue described in https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/java_simpledateformat_vs_xs_datetime26?lang=en, but again unsuccessful. Any solution?

Community
  • 1
  • 1
Edi
  • 109
  • 11
  • 1
    call `s.substring(s.lastIndexOf(' ') + 1)`, and parse the result? – JB Nizet Apr 20 '15 at 22:26
  • with SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS")? – Edi Apr 20 '15 at 22:28
  • Yes, that seems like the right pattern. – JB Nizet Apr 20 '15 at 22:32
  • I tried that and got IllegalArgumentException: Cannot format given Object as a Date – Edi Apr 20 '15 at 22:35
  • Post your code. I just tested it, and it works fine here. – JB Nizet Apr 20 '15 at 22:35
  • `String s1 ="~@http://www.w3.org/2001/XMLSchema#dateTime 2015-04-18T07:52:53.653"; String part = s1.substring(s1.lastIndexOf(' ') + 1); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");System.out.println(fmt.format(part));` – Edi Apr 20 '15 at 22:41
  • 1
    You're trying to format a String. That doesn't make sense. `format()` takes a Date, and produces a String. `parse()` takes a String, and produces a Date. – JB Nizet Apr 20 '15 at 22:42
  • You're right @JBNizet I mixed the notions. I used parse() and it gave me the result. Thank you – Edi Apr 20 '15 at 22:51

0 Answers0