getHour() from database Datetime datatype
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sathish_S
Posted On:   Thursday, April 12, 2001 01:32 PM

Hi,
I have a datetime column in the database.
I need to extract the hour from that value ? How can I do this ?
The docs say that
java.sql.Time.getHours() is deprecated and suggests using calendar instead.
How to do this using Calendar.
Thanks,
Sathish

Re: getHour() from database Datetime datatype

Posted By:   AlessandroA_Garbagnati  
Posted On:   Thursday, April 12, 2001 02:42 PM

Hi,

Yes, since Java 1.1, some of the java.util.Date have been deprecated for a more powerful solution with the addition of java.util.Calendar and java.text.dateFormat. Please refer to the javadocs for more specific information.


To answer your question, one possible way to get the hour is:



Calendar cal = new GregorianCalendar();

cal.setTime(resultSet.getTimeStamp(""));

int hour = cal.get(Calendar.HOUR);

[or] int hour = cal.get(Calendar.HOUR_OF_DAY);


About | Sitemap | Contact