Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
TimeZone is not part of the state of Date object. Think of a Date object as just a timestamp -- the number of milliseconds since midnight, 1 Jan 1970 GMT. Unfortunately, Date's toString method formats itself using your JVM default TimeZone. (I'd rather have it's toString method return this raw long value.)
Anyway, I think the solution to do your formatting explicitly, using DateFormat:
that is interesting, but I need the code to be generic, so i don't know what timezone will be where/when the program is ran. The problem is that Calendar has the method getTimeInMillis() - which should be the timestamp, why else is it there? so a call like new Date(calendar.getTimeInMillis()) should print the same date, but it doesn't. otherwise, there should be getTimeInMillisandgetTimeInMillisNoTimeZone or getTimeZoneMillis.
using DateFormat to "translate" a Calendar to a Date is just as un-elegant as
An xml parser retrieves for me a Calendar object by reading a file (the file was created in another timezone). I need to pass this time to a constructor of another class but as a Date. The problem is that in debug I see that the Calendar (actually XmlCalendar) instance is 2006-04-05T00:00:00.000+03:00 - so it is correct and when I do a new Date(calendar.getTimeInMillis()) in debug the date is: Tue Apr 04 21:00:00 GMT 2006 - but normally it should be the same date, april 5th,00:00
I can only retrieve the correct time as a Date by doing new Date(calendar.getTimeInMillis() + calendar.get(Calendar.ZONE_OFFSET))
You write that your Calendar is 2006-04-05T00:00:00.000+03:00. With all those zeroes am I right in assuming this element/attribute in your XML file is intended to specify a year, month and day, but no more information? That it's no indended to specify hour, minute, second, milliseconds or time zone? And how is the field formatted in the original XML file? Is it formatted with time zone information? If the answer is yes to both these questions, it sounds like the XML file is misformatted. It should contain a field like "2006-04-05" only.