Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Red Oktober
May 24, 2006

wiggly eyes!



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?

Adbot
ADBOT LOVES YOU

Red Oktober
May 24, 2006

wiggly eyes!



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!

Red Oktober
May 24, 2006

wiggly eyes!



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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply