In this example, you will see the use of getHours() and getMinutes() method of Date class in java.
Use of getHours() and getMinutes() method of Date class in java.
Here, you will see the implementation of getHours() and getMinutes() method of java Date class. It returns the hours represented by this date object. The value of hours is 0 to 23. It returns the minutes represented by this date object.
Code:
import java.text.SimpleDateFormat; import java.util.Date; public class GetHourgetMinutesMethod { public static void main(String[] arr) { Date obDate = new Date(); SimpleDateFormat obDateFormat = new SimpleDateFormat( "yyyy-MM-dd hh:MM:dd a"); System.out.println("Current Date of system :" + obDateFormat.format(obDate.getTime())); System.out.println("Hours of given date : " + obDate.getHours()); System.out.println("Minuts of given date : " + obDate.getMinutes()); } }Output
Current Date of system : 2010-11-25 04:11:25 PM Hours of given date : 16 Minuts of given date : 11 |
[ 0 ] Comments