java get current hour

Solutions on MaxInterview for java get current hour by the best coders in the world

showing results for - "java get current hour"
Emma
25 Sep 2016
1Try using Joda Time instead of standard java.util.Date classes. Joda Time library has much better API for handling dates.
2
3DateTime dt = new DateTime();  // current time
4int month = dt.getMonth();     // gets the current month
5int hours = dt.getHourOfDay(); // gets hour of day
6See this question for pros and cons of using Joda Time library.
7
8Joda Time may also be included to some future version of Java as a standard component, see JSR-310.
9
10If you must use traditional java.util.Date and java.util.Calendar classes, see their JavaDoc's for help (java.util.Calendar and java.util.Date).
11
12You can use the traditional classes like this to fetch fields from given Date instance.
13
14Date date = new Date();   // given date
15Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
16calendar.setTime(date);   // assigns calendar to given date 
17calendar.get(Calendar.HOUR_OF_DAY); // gets hour in 24h format
18calendar.get(Calendar.HOUR);        // gets hour in 12h format
19calendar.get(Calendar.MONTH);       // gets month number, NOTE this is zero based!
queries leading to this page
put hour in date javajava get hour from datejava get current day and hourjava get time hour and minutejava date get hoursjava get hour of dayjava get time hours minutes secondsjava get hour get hour from date time javaget hour from localdate javajava get hoursjava date get hourcalendar java get hourget hour and minute javaget hour in date javahow to get hour from pc javajava get full current time in minutesget the hour from a date javajava how to get hour get hour from datetime javaget hour from date javaget current hour and minute in javaget hour java 8set current hour in javajava get current hourget current hour javajava date get current minutesget current hour in javacalendar gettime 28 29 get hour in javajava time get hourjava show current time in hours and minuteshow to get the current hour in javaget hour from calendar javalocaltime current hour javaget the current hour javadate get set hour javaget current hour in javasget current time hours and seconds javajava get current time hour minute seconddate get hour javaget hour from java datejava get current hour and minutesjava get current datetime get minutesjava get current time in hourget hour javajava get current time hours minutesget hour java instanjava get current time in minutesjava get current hour and minutedate get hours javajava get current time hourhow to get current hours and minutes in javahow get hour in date javajava get hour in military timejava get hour francejava get current hoursjava get current hour