It seems a Javascript date in String, but how to format it to a java.util.Date
? Is it possible by SimpleDateFormat
?
Okay, I didn't read it carefully.
It seems a Javascript date in String, but how to format it to a java.util.Date
? Is it possible by SimpleDateFormat
?
Okay, I didn't read it carefully.
One of the examples mentioned in the documentation exactly matches your case:
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" 2001-07-04T12:08:56.235-07:00
So
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").parse(yourString);
will give what you want.
The pattern of javascript
date you are getting is
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" 2001-07-04T12:08:56.235-07:00
in terms of java
.
Use the sample code:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.SimpleDateFormat;
class Test
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
System.out.println(sdf.parse("2015-08-01T06:51:14.000+08:00"));
Date date = sdf.parse("2015-08-01T06:51:14.000+08:00");
}
}
From the API documentation of SimpleDateFormat (see the examples), the pattern to use in your case is:
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
Bear in mind that using Z instead of XXX only works if time zone is written as -0700 (no colon).