First, a remark about these lines in your code:
Note that the method
getTimeZone() of class
TimeZone is a static method. You do not need to call that method on an instance of
TimeZone (and, as James said, "GMT Time" is not a valid timezone identifier). Just do this:
Ashu Bharadwaj wrote:However, I wanted the Calendar objects's date to be assigned to the timestamp.
Your code is already doing exactly that in this line:
Ashu Bharadwaj wrote:When I display the TimeStamp it shows : 11:45:20 , which is IST, (I want it to display 05:15:20 GMT )
Yes, because Timestamp objects (just like java.util.Date) do not contain any timezone information. A Timestamp represents an "absolute" moment in time, without timezone information. When you print it with
System.out.println(...);,
Java will format it with the default timezone of the system (which happens to be IST on your system). If you want to display it in a different timezone, you must use a
DateFormat object on which you set the desired timezone, and use that to format your Timestamp. For example: