get Hour Of Day - Android java.util

Android examples for java.util:Hour

Description

get Hour Of Day

Demo Code


//package com.java2s;

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

public class Main {
    public static int getHourOfDay(Date time) {
        return getTimeField(time, Calendar.HOUR_OF_DAY);
    }//from  w ww .  ja  v  a 2  s.  c  o  m

    private static int getTimeField(Date time, int field) {
        Calendar calendar = GregorianCalendar.getInstance();
        calendar.setTime(time);
        return calendar.get(field);
    }
}

Related Tutorials