如何将公历字符串转换为公历?

How to convert Gregorian string to Gregorian Calendar?(如何将公历字符串转换为公历?)
本文介绍了如何将公历字符串转换为公历?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

例如 i/p 收到 {may be - "new GregorianCalendar().toString()"} as String :- 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,minimalDaysInFirstWeek=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]

我想提取日历的日期值来处理进一步的计算.

I want to extract the Calendar's date value to process further computation.

推荐答案

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

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));
}

这篇关于如何将公历字符串转换为公历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Month is not printed from a date - Java DateFormat(月份不是从日期打印的 - Java DateFormat)
java get week of year for given a date(java获取给定日期的一年中的一周)
Get the number of days, weeks, and months, since Epoch in Java(获取自 Java 中的 Epoch 以来的天数、周数和月数)
Is there a good way to get the date of the coming Wednesday?(有什么好方法可以得到即将到来的星期三的日期吗?)
Calendar view for Android GingerBread and before (APIlt;11)(Android GingerBread 及之前的日历视图 (API11))
How to save and retrieve Date in SharedPreferences(如何在 SharedPreferences 中保存和检索日期)