Java Calendar Hour getHour(Calendar cal)

Here you can find the source of getHour(Calendar cal)

Description

get Hour

License

Open Source License

Declaration

public static String getHour(Calendar cal) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {

    public static String getHour(Calendar cal) {
        return strLen(String.valueOf(cal.get(Calendar.HOUR_OF_DAY)), 2);
    }// w ww  . j  av a 2  s. co m

    public static int getHour(String s) {
        if (s == null || s.length() < 16) {
            return 0;
        }
        return Integer.parseInt(s.substring(11, 13));
    }

    private static String strLen(String s, int len) {
        if (isNullStr(s)) {
            s = "";
        }
        if (s.length() == 8) {
            return s;
        }
        for (int i = 0; i < len - s.length(); i++) {
            s = "0" + s;
            if (s.length() == 8) {
                break;
            }
        }
        return s;
    }

    private static boolean isNullStr(String s) {
        if (s == null || s.trim().length() <= 0) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. elapsedHours(Calendar aFirstDate, Calendar aSecondDate)
  2. get24Hour(Calendar calendar)
  3. getHour(boolean twentyFour, Calendar calendar)
  4. getHour(Calendar cal)
  5. getHour(Calendar calendar)
  6. hour(Calendar calendar)
  7. hourFloor(Calendar calendar)
  8. hoursInDay(Calendar cal)