What you are doing is choosing a second when it is 23:59:59 where you are. But the Timestamp may interpret that time as GMT/UTC, so you get 9:29:59 on 30th October.
Anybody else like to explain it better than I did?
Look at the javadocs for this constructor:
Constructs a Timestamp object using a milliseconds time value. The integral seconds are stored in the underlying date value; the fractional seconds are stored in the nanos field of the Timestamp object.
time milliseconds since January 1, 1970, 00:00:00 GMT. A negative number is the number of milliseconds before January 1, 1970, 00:00:00 GMT.
The important bit here is the number of milliseconds before January 1, 1970, 00:00:00 GMT
As you have specified a timezone of "Brazil/West", the value of cal.getTimeInMillis() is 1383105599000. If you change the timezone to "GMT", the value of cal.getTimeInMillis() is 1383177599000.
This explains why the output is not 2013-10-30 23:59:59.0
Hrithik khurana wrote:Why is the time not setting to MidNight. Please help!!
It is setting it to midnight, but midnight in the timezone Brazil/West is not midnight in your local timezone. Apparently, the time is 09:29:59 in your local timezone when it is 23:59:59 in the timezone Brazil/West.
If you want to see the time in the Brazil/West timezone, you need to format it with a DateFormat object that is set to that timezone. Note that a Timestamp object by itself doesn't have (explicit) timezone information. If you print a Timestamp object directly, it will be formatted with a default date formatter that will show it in your local timezone, so the time it will show is not midnight if your local timezone is not Brazil/West.