You haven't shown us enough code to know what's going on, but your output is very easy to explain: you're calling Date.toString()
which always formats the instant in time using the system local time zone. The time zone in the Calendar
object is irrelevant.
So it looks like your Calendar
may be in UTC for example, in which case the day is 15.
Note that the first line of your log is clearly nonsense:
UTC time: Fri Nov 15 00:28:44 EST 2013
It's either UTC or it's EST. It can't be both.
It's not clear where your data comes from or exactly how you're dealing with it, but if you're manually adjusting the date/time by adding or subtracting parts, you're almost certainly doing it wrong. It's very important to understand that a java.util.Date
doesn't have any notion of a time zone as part of its data - it's just an instant in time.
To format a Date
in a particular time zone, you'd usually use a SimpleDateFormat
and specify the time zone on that. For example:
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("America/New_York"));
System.out.println("The time in New York is " + format.format(new Date()));
EDIT: Now that we've seen your code, you should definitely not do things that way. You're adjusting the point in time, which isn't what you want - you only want to change your view on the same point in time, which can be achieved using Calendar.setTimeZone
to change what's returned by Calendar.get
, and using DateFormat.setTimeZone
to change which time zone is used for parsing/formatting text.