Forums Register Login

TimeStamp.toString() does not work as expected

+Pie Number of slices to send: Send
Hi,

I created a Calendar object and assigned some date to the Calendar object. Now I constructed TimeStamp using the Calendar object. The constructed TimeStamp gets the current time of the system in millis. However, I wanted the Calendar objects's date to be assigned to the timestamp.
See the code

+Pie Number of slices to send: Send
Is your problem with the Timestamp#toString() method, or do you wish to change the date to show 00:00:00.00 as the time Do you need to set hours minutes and seconds to 0 on the Calendar object before passing it to the Timestamp?

And which TimeStamp do you mean?There is no TimeStamp in the Oracle API but there are two Timestamp classes.
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:Is your problem with the Timestamp#toString() method, or do you wish to change the date to show 00:00:00.00 as the time Do you need to set hours minutes and seconds to 0 on the Calendar object before passing it to the Timestamp?

And which TimeStamp do you mean?There is no TimeStamp in the Oracle API but there are two Timestamp classes.



Thanks for your response.

What I intend to do is that convert Calendar object to TimeStamp. In the code I created a Calendar object calendar and time it has is in GMT , e.g., 05:15:20.
(current GMT)

When I display the TimeStamp it shows : 11:45:20 , which is IST, (I want it to display 05:15:20 GMT )
+Pie Number of slices to send: Send
I don't recognise
as a valid time zone name! To find the valid GMT zones



Also, I would use SimpleDateFormat setting the time zone to format a date.
+Pie Number of slices to send: Send
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:

I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4323 times.
Similar Threads
Date Parsing Issue...
Changing TimeZone of Date.
How to display date in Daylight Savings
Change Timezone from GMT to EST, the best way to accomplish?
Convert the String to date format
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:48:58.