编程语言
首页 > 编程语言> > java-如何将阳历字符串转换为阳历?

java-如何将阳历字符串转换为阳历?

作者:互联网

我必须根据日历的日期计算出一些东西,但是我收到了完整的公历日历的字符串值.

例如,接收到的i / p {可能是-“ new GregorianCalendar().toString()”}作为字符串:-java.util.GregorianCalendar [time = 1410521241348,areFieldsSet = true,areAllFieldsSet = true,lenient = true,zone = sun. util.calendar.ZoneInfo [id =“ Europe / London”,offset = 0,dstSavings = 3600000,useDaylight = true,transitions = 242,lastRule = java.util.SimpleTimeZone [id = Europe / London,offset = 0,dstSavings = 3600000,useDaylight = true,startYear = 0,startMode = 2,startMonth = 2,startDay = -1,startDayOfWeek = 1,startTime = 3600000,startTimeMode = 2,endMode = 2,endMonth = 9,endDay = -1,endDayOfWeek = 1,endTime = 3600000,endTimeMode = 2]],firstDayOfWeek = 1,minimumDaysInFirstWeek = 1,ERA = 1,YEAR = 2014,MONTH = 8,WEEK_OF_YEAR = 37,WEEK_OF_MONTH = 2,DAY_OF_MONTH = 12,DAY_OF_YEAR = 255,DAY_OF_WEEK = 6,DAY_OF_WEEK_IN_MONTH = 2,AM_PM = 1,HOUR = 0,HOUR_OF_DAY = 12,MINUTE = 27,SECOND = 21,MILLISECOND = 348,ZONE_OFFSET = 0,DST_OFFSET = 3600000]

我想提取日历的日期值以进行进一步的计算.

解决方法:

其他答案过于复杂或错误.以下将为您提供自纪元以来的毫秒数,这是一个通用时间戳,您可以轻松地将其转换为大多数时间表示形式,包括Calendar或Date:

Pattern gregorianPattern = Pattern.compile("^java.util.GregorianCalendar\\[time=(\\d+).*"); 

Matcher matcher = gregorianPattern.matcher(param);
if(matcher.matches()) {
    return Long.parseLong(matcher.group(1));
}

标签:gregorian-calendar,calendar,java-ee-7,java
来源: https://codeday.me/bug/20191121/2050523.html