Javatpoint Logo
Javatpoint Logo

Java SQL Date setHours(inti) Method

The setHours(int i) method of Java Date class sets the value of hour by overwriting the value of hour represented by this date. This method should not be used because SQL date values do not have the time component and this method is deprecated too. This method overrides setHours in class Date.

Syntax

Parameters

i = It is the hour value

Exception

IllegalArgumentException is thrown if this method is invoked.

Example

Test it Now

Output:

!! this output is shown by using java.util.Date as an alternate to deprecated method java.sql.Date
Current time in hours = 21
!! this output is shown by using java.sql.Date and proves why this method is deprecated and we can't access time components in java.sql.Date class. 
Exception in thread "main" java.lang.IllegalArgumentException
	atjava.sql/java.sql.Date.setHours(Unknown Source)
	at date.JavaDateExample1.main(JavaDateExample1.java:26)

Next TopicJava SQL Date





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA