Search code examples
javajsondatetimedate-conversion

Convert Json date to java calendar


I have the following value /Date(1234043600000)/ in string type and I need to convert it to java calendar type without a success,I have tried to use the following post and create date and than do something like the post

How do I format a Microsoft JSON date?

Date date = new Date(parseInt(jsonDate.substr(6))); 

and than do someting like

Calendar cal = Calendar.getInstance();
cal.setTime(date);

I got error in the first line since in the word date i have line in the middle and substr(6) have error (The method substr(int) is undefined for the type String) ,how should I continue .

Thanks!


Solution

  • This should work in Java

    Date date = new Date(Long.parseLong(jsonDate.replaceAll(".*?(\\d+).*", "$1")));
    

    the problem with your example is that it's only good for javascript