Java Hour getHour(Date d)

Here you can find the source of getHour(Date d)

Description

Hour: 1 - 12

License

Open Source License

Declaration

public static int getHour(Date d) 

Method Source Code

//package com.java2s;

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

public class Main {
    /** Hour: 1 - 12 */
    public static int getHour(Date d) {
        Calendar c = getCalendar();
        c.setTime(d);/*from ww  w .  j  a  v a  2s  .c o m*/
        return (c.get(Calendar.HOUR));
    }

    /**
     * month ranges from 1 to 12 (not 0 to 11)
     */
    private static Calendar getCalendar() {
        return (getCalendar(null, null));
    }

    private static Calendar getCalendar(TimeZone timeZone, Locale locale) {
        if (timeZone == null)
            timeZone = TimeZone.getDefault();

        if (locale == null)
            locale = Locale.getDefault();

        Calendar c = new GregorianCalendar(timeZone, locale);
        return (c);
    }

    public static Date setTime(Date d, long time) {
        d.setTime(time);
        return (d);
    }
}

Related

  1. getHour()
  2. getHour()
  3. getHour(boolean military)
  4. getHour(Date begin, Date end)
  5. getHour(Date d)
  6. getHour(Date d)
  7. getHour(Date date)
  8. getHour(Date date)
  9. getHour(Date date)