Get Day,Month,Hours,Minute from a given Timestamp

Hi ,

     For example , the timestamp  is given as "2003-04-05-"

   How can I  retrieve the minutes,day,seconds from the given timestamp.

  I tried to retrieve it by using
   java.sql.Timestamp  actcmpStmp =  "2003-04-05-";

   int runday = actcmpStmp.getMinutes();
   But the methods used above are   DEPRECATED.
How can I retrieve seconds, minutes,day, etc from a given Timestamp without using Depracted Methods.
 Can anyone help me in this regard.

Who is Participating?
objectsConnect With a Mentor Commented:
DateFormat sdf = new SimpleDateFormat("");
Date d = sdf.parse("2003-04-05-");
Calendar cal = cal.getInstance();
int minutes = cal.get(Calendar.MINUTE);
int day = cal.get(Calendar.DAY_OF_MONTH);
int seconds = cal.get(Calendar.SECOND);

>> DateFormat sdf = new SimpleDateFormat("");
DateFormat sdf = new SimpleDateFormat(""); //missed one y

Also, use H instead of h if this the hour is from 0  to 23 (as it seems so)
bare in mind that cal.get(Calendar.MONTH) returns a value from 0 to 11 (just add 1 to the returned value)
Note that SimpleDateFormat is not Thread safe.

For more info see:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.