Java Hour getCurrentHour()

Here you can find the source of getCurrentHour()

Description

get Current Hour

License

Apache License

Declaration

public static Date getCurrentHour() 

Method Source Code


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

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

public class Main {
    public static Date getCurrentHour() {
        Calendar cal = Calendar.getInstance();

        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        return cal.getTime();
    }//from w w  w . ja v a  2 s .  c  om

    public static Date getCurrentHour(int index) {
        Calendar cal = Calendar.getInstance();

        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.HOUR_OF_DAY, index);

        return cal.getTime();
    }
}

Related

  1. getAnHourBack()
  2. getBeforeOneHour()
  3. getCalenderWithHour(int hours)
  4. getCurrentHour()
  5. getCurrentHour()
  6. getCurrentHours()
  7. getCurrHour()
  8. getDelay(int hour, int min)
  9. getDelayToNextHour(int amount, boolean skipNext)