The java.util.Date class provides a set of methods to manipulate different parts of a date/time object. One of these methods is the setHours() method, which allows you to set the hour of the day for a given date object.
Here are some examples of how to use the setHours() method:
Example 1: Set the hour of the day to 12pm (noon)
Date date = new Date();
date.setHours(12);
Example 2: Set the hour of the day to 8am
Date date = new Date();
date.setHours(8);
Example 3: Set the hour of the day to 10pm
Date date = new Date();
date.setHours(22);
All these examples are part of the java.util package library.
Java Date.setHours - 30 examples found. These are the top rated real world Java examples of java.util.Date.setHours extracted from open source projects. You can rate examples to help us improve the quality of examples.