• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I convert a Timestamp to a Calendar?

 
keith tyson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic