Android Hour Get isBeforeHourTime(String compactTime, int hour)

Here you can find the source of isBeforeHourTime(String compactTime, int hour)

Description

is Before Hour Time

Declaration

public static boolean isBeforeHourTime(String compactTime, int hour) 

Method Source Code

//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.util.GregorianCalendar;
import android.util.Log;

public class Main {
    private static final String TAG = "DateTimeUtil";

    public static boolean isBeforeHourTime(String compactTime, int hour) {
        Log.d(TAG, "compateTime: " + compactTime);
        if (compactTime.trim().length() < 14) {
            /** Illegal format look as original time */
            return true;
        }// www.  j  av  a2  s. c o  m

        String beforeTime = addHourTime(hour);
        Log.d(TAG, "beforeTime: " + beforeTime);
        if (compactTime.compareTo(beforeTime) < 0) {
            return true;
        } else {
            return false;
        }
    }

    public static String addHourTime(int hour) {
        GregorianCalendar gcalendar = new GregorianCalendar();
        gcalendar.add(Calendar.HOUR, hour);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        return sdf.format(gcalendar.getTime());
    }
}

Related

  1. getHour()
  2. betweenHours(int tuntil_h, int tfrom_h, int tuntil_m, int tfrom_m, int c_hour, int c_min)