Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to extract hours and minutes from date retrieved from database

807600May 23 2007 — edited May 24 2007
hi all

i want to extract hours and minute from the date taken from the database. so i wrote following code

java.util.Date createddate; or java.sql.Date createddate;
createddate=rs1.getDate("CreatedDate");

Calendar cal = Calendar.getInstance();
cal.setTime(createddate);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
month=month+1;
int day = cal.get(Calendar.DATE);
int hour = cal.get(Calendar.HOUR);
int min= cal.get(Calendar.MINUTE);
String result=month +" "+day+" "+year + " " hour ":"+min;


When i printed the above string "result"in JSP i got the following result

5 7 2007 0:0

i am able to get the month,year, date but i am not able to get the hours and minutes.It is showing me time and minutes as o and o. I had created the CreatedDate column as date datatype in oracle

can any body help me to solve this problem


Regards
andy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2007
Added on May 23 2007
2 comments
615 views