Convert Json date to java calendar

让人想犯罪 __ 提交于 2019-12-01 11:21:16

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

The easiest way for you to get the number is to use

Long dateInMiliSeconds = new Scanner(jsonDate).nextLong();
Date date = new Date(dateInMiliSeconds);
Calendar cal = Calendar.getInstance();
cal.setTime(date);

Also the reason for your compilation error is that the method to get a sub string in Java String class is called subString not substr.

Although using the scanner is cleaner if you don't know much regex Evgeniy's answer may be better performance wise. I have no idea about the two approaches performance differences.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!