Alternate method for setHours() of java.util.Date?
java
Solution
Try this:
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hour);
Date date = cal.getTime();
If you have a `Date` object already, you can use `cal.setTime(date)` to initialize calendar with the given date.
JavaDoc for `Calendar.HOUR_OF_DAY`
Field number for get and set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.
Problem
What is an alternate method for `setHours()` of `java.util.Date` as it is deprecated. To my date variable, I want to set certain hours but I don't want to use the deprecated method `setHours()`.