How to convert Gregorian string to Gregorian Calendar?

后端 未结 3 1133
醉话见心
醉话见心 2020-12-19 22:51

I have to compute something based on the Calendar\'s date, but I am receiving the complete Gregorian Calendar\'s String value.

Eg i/p received {may be - \"new

3条回答
  •  心在旅途
    2020-12-19 23:34

    Other answers are too complicated or wrong. The following will give you the milliseconds since the epoch, which is a universal timestamp that you can easily convert to most time representation classes, including Calendar or Date:

    Pattern gregorianPattern = Pattern.compile("^java.util.GregorianCalendar\\[time=(\\d+).*"); 
    
    Matcher matcher = gregorianPattern.matcher(param);
    if(matcher.matches()) {
        return Long.parseLong(matcher.group(1));
    }
    

提交回复
热议问题