Prabhakar Pentela
Prabhakar Pentela

Reputation: 5

Setting timestamp to Calendar in java

I am using following code to set SQL timestamp in calendar instance, it is working fine. Is this correct?

 TimeStamp expireDate= ab.getUExpireDate();
 Calendar cal = Calendar.getInstance(); 
 cal.setTime(expireDate); // ← this line

Upvotes: 0

Views: 1780

Answers (2)

Dawlatzai Ghousi
Dawlatzai Ghousi

Reputation: 3978

You can import:

1)java.sql.Timestamp

***The biggest difference between java.sql.Date and java.sql.Timestamp is that the java.sql.Date only keeps the date, not the time, of the date it represents. So, for instance, if you create a java.sql.Date using the date and time 2014-12-24 21:20, then the time (21:20) would be cut off. If you use a java.sql.Timestamp then the time is kept.

method to add timeStamp object in Calender is :

2) cal.setTime(expireDate);

Upvotes: 0

sumitsabhnani
sumitsabhnani

Reputation: 320

You can check the difference in util.Date and sql.Date in the following post

java.util.Date vs java.sql.Date

Upvotes: 1

Related Questions