kitokid
kitokid

Reputation: 3117

add 23hr 55 sec to timestamp object java

How can I add 23 hr 59 min to the timestamp object which will be converted to Date object in java?

I want to get for example 2011-12-08 23:59:59.0

As I get the timestamp from pop up calender, I always get 2011-12-08 00:00:00.0 like this. That's why.

Thanks.

Upvotes: 0

Views: 153

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94645

First of all obtain the Calendar instance and use setTimeInMillis() method to set timestamp's time.

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestampObj.getTime());
cal.add(Calendar.HOUR, 23);
cal.add(Calendar.SECOND, 55);
Date date=cal.getTime();

Upvotes: 4

Related Questions