|
I'm horribly confused with Calendar objects in java. At the minute I'm parsing a file off the internet which has a couple of fields like: "2/6/2008","4:00pm" to represent times. I think pick these out into a set of fields, year, month, day, hour and minutes with a parser. I get a new instance of Calendar. (calendar = calendar.getCalendar()); clear it (calendar.clear()) and set it calendar.set(year, month, day, hour, minutes); However, when I attempt to get the millisecond value, it appears to be wrong by about a month. To check I used the calendar.toString(); method, and got this: java.util.GregorianCalendar[time=1209221820000,areFieldsSet=true,areAllFieldsSet=false, 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=?,YEAR=2008,MONTH=3,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=26,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=15,MINUTE=57,SECOND=?,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?] 1209221820000 as a millisecond time is Sat, 26 Apr 2008 14:57:00 GMT, but the toString method also gives the correct time, the 26th of March 2008 at 15:57 GMT. I'm sure I can solve the hour (BST or DST or something) but the entire month off is stumping me. Any have any ideas?
|
# ¿ Mar 27, 2008 01:42 |
|
|
# ¿ May 6, 2024 06:04 |
|
10011 posted:January is month zero, so you'll need to subtract one from the months before setting the calendar. :facepalm: I've spent far too long looking at this, thank you!
|
# ¿ Mar 27, 2008 13:08 |
|
ShinAli posted:It pops up randomly, but sometimes it doesn't recognize a class in the entire code or just a single line. I clean and build and everything but it doesn't go away. I might have the error too, if you add a space in front of the 'package a.b.c;' to make it ' package a.b.c;', does it go away? Because if so, that's the only means I've found of getting rid of it.
|
# ¿ Apr 15, 2008 18:10 |