我试图像这样将axis.types.Time转换为sql.Time:

    org.apache.axis.types.Time axisTime = (org.apache.axis.types.Time) valore;
    Calendar calendarTime = axisTime.getAsCalendar();
    java.sql.Time jsqlT = java.sql.Time.valueOf( cal.get(cal.HOUR_OF_DAY) + ":" +  cal.get(cal.MINUTE) + ":" + cal.get(cal.SECOND) );


但是我之间的转换相差一小时。这与白天相关吗?我该如何解决?

(输出:
轴时间:20:45:00.000Z

日历:java.util.GregorianCalendar[time=-62167403700000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,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=2,minimalDaysInFirstWeek=4,ERA=0,YEAR=2,MONTH=11,WEEK_OF_YEAR=1,WEEK_OF_MONTH=5,DAY_OF_MONTH=31,DAY_OF_YEAR=365,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=5,AM_PM=1,HOUR=9,HOUR_OF_DAY=21,MINUTE=45,SECOND=0,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]

SQLTIME 21:45:00

编辑:我通过使用字符串解决了这个问题...但是此axis-date / time对象与日光和时区不是很友好,DateTime对象的麻烦甚至更糟(再次,我强迫解决方案忽略了GMT / Daylights和使用字符串)

最佳答案

尝试以下方法:

org.apache.axis.types.Time axisTime = (org.apache.axis.types.Time) valore;
Calendar calendarTime = axisTime.getAsCalendar();
java.sql.Time jsqlT = new java.sql.Time(calendarTime.getTimeInMillis());


这样,您就不会在夏令时更改方面遇到任何问题。

关于java - AxisTime到Java时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11397708/

10-11 02:21