aspose file tools
The moose likes JDBC and the fly likes How do I convert a Timestamp to a Calendar? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How do I convert a Timestamp to a Calendar?" Watch "How do I convert a Timestamp to a Calendar?" New topic
Author

How do I convert a Timestamp to a Calendar?

keith tyson
Greenhorn

Joined: Sep 28, 2001
Posts: 7
I have a method that returns a Timestamp and I need to pass this to a method that is expecting a Calendar object.
ie.
deliveryDetails.getWindowStart() // returns a Timestamp
and I need to pass another method this value as a Calendar.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Calendar cal = Calendar.getInstance();
cal.setTime(timestamp);
This will give a Calendar object that has the correct time, but unfortunately it will also set the Date portion to the 1st of January 1970. If you need to get rid of that,
cal.clear(Calendar.YEAR);
cal.clear(Calendar.DAY_OF_YEAR);
Should do it.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I convert a Timestamp to a Calendar?
 
Similar Threads
How do I convert a Timestamp to a Calendar?
How do i convert a Date object into a Timestamp object ?
How do i convert a Date object into a TimeStamp object
TimeStamp.toString() does not work as expected
How do i convert a Date object into a Timestamp object ?