January 2 2017

Java calendar hour_of_day

Java calendar hour_of_day

Set the Calendar object to the date for which you need the calendar hour of day, Calendar .get(Calendar. HOUR_OF_DAY) will give you hour of the day in 24 hour clock. E.g. 01:15:35 PM the HOUR_OF_DAY is 13.

Example


package com.answersz;

import java.util.Calendar;
import java.util.Date;

public class JavaCalendarHourOfDay {

public static void main(String[] args) {

// Java calendar hour_of_day

Date dt = new Date();

Calendar cal = Calendar.getInstance();
 cal.setTime(dt);

int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);

System.out.println("Date : " + dt);
 System.out.println("Calendar hour of day : " + hourOfDay);

}
}

Output

Date : Mon Jan 02 14:00:18 IST 2017
Calendar hour of day : 14


Copyright © 2014. All rights reserved.

Posted January 2, 2017 by answersz in category Core Java

Leave a Comment

Your email address will not be published. Required fields are marked *

*