我正在尝试使用javax.xml.bind.DatatypeConverter.parseDateTime()将格里高利日期转换为字符串,这会抛出非法的参数异常
以下是代码:
public Calendar getDate()
{
String date = (getPObj("Date")).toString();
System.out.println(date);
return date == null ? null : javax.xml.bind.DatatypeConverter.parseDateTime(date);
}
输出:
date :java.util.GregorianCalendar[time=1422556781908,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2015,MONTH=0,WEEK_OF_YEAR=5,WEEK_OF_MONTH=5,DAY_OF_MONTH=29,DAY_OF_YEAR=29,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=5,AM_PM=1,HOUR=1,HOUR_OF_DAY=13,MINUTE=39,SECOND=41,MILLISECOND=908,ZONE_OFFSET=-18000000,DST_OFFSET=0]
getPObj(" Date")以格里高利格式返回日期
任何帮助将不胜感激
由于
答案 0 :(得分:0)
API的签名为public static java.util.Calendar parseDateTime(java.lang.String lexicalXSDDateTime)
,并提到它会抛出IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:dateTime.
在您的情况下,您需要更改字符串表示。