Java Hour getHour(Date date)

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

Description

get Hour

License

Apache License

Declaration

public static Integer getHour(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Integer getHour(Date date) {
        if (date == null)
            return null;
        String hour = format(date, "H");
        return Integer.parseInt(hour);
    }//w w w  .  jav  a  2 s .c  o  m

    /**
      * @param date
      * @param pattern: Date format pattern
      * @return
      */
    public static final <T extends Date> String format(T date, String pattern) {
        if (date == null)
            return null;
        try {
            SimpleDateFormat df = new SimpleDateFormat(pattern);
            String result = df.format(date);
            return result;
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. getHour(Date date)
  2. getHour(Date date)
  3. getHour(Date date)
  4. getHour(Date date)
  5. getHour(Date date)
  6. getHour(Date now)
  7. getHour(final Date timeFrom)
  8. getHour(java.util.Date date)
  9. getHour(long t)