Java Utililty Methods Hour

List of utility methods to do Hour

Description

The list of methods to do Hour are organized into topic(s).

Method

longgetTicksTill(int hour)
Gets the ticks till a given base 24 hour
return getTicksTill(hour, -1);
longgetTicksTillHour()
Gets the ticks till the start of the next hour
Calendar localCalendar = Calendar.getInstance();
long returnValue;
localCalendar.set(Calendar.MINUTE, 0);
localCalendar.add(Calendar.HOUR_OF_DAY, 1);
returnValue = localCalendar.getTimeInMillis() - calendar.getTimeInMillis();
returnValue = (returnValue / 1000) * 20; 
return returnValue;
inthour()
Returns the current hour as a value from 0 - 23.
return new GregorianCalendar().get(Calendar.HOUR_OF_DAY);
inthour()
hour
return calendar().get(Calendar.HOUR);
DatehourAgo()
Get date for hour ago from now
return forCalendarDiff(Calendar.HOUR, -1);
StringhourCompletion(boolean hourPresent, int hour, boolean minutePresent, int minute, boolean secondPresent, int second, boolean milliPresent, int milli, String choice)
hour Completion
String result = new String();
if (!choice.equals("hour") && !choice.equals("minute") && !choice.equals("second")
        && !choice.equals("milli"))
    throw new RuntimeException("Unrecognize parameter 'choice'");
Calendar calendar = Calendar.getInstance();
int state;
if (hourPresent) {
    if (minutePresent) {
...
StringHourNow()
Hour Now
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int min = Calendar.getInstance().get(Calendar.MINUTE);
int sec = Calendar.getInstance().get(Calendar.SECOND);
return "[" + hour + ":" + min + ":" + sec + "]";
StringHours()
Hours
Calendar c = Calendar.getInstance();
c.setTime(new Date());
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
return year + "-" + (month < 10 ? "0" : "") + month + "-" + (date < 10 ? "0" : "") + date + "-"
        + (hour < 10 ? "0" : "") + hour;
...
Datehours(int hours)
hours
return hours(new Date(), hours);
inthoursAndMinsToMilliseconds(int sign, int hours, int minutes)

Converts a number of hours, minutes and seconds and a corresponding sign value to an equivalent offset value from UTC (Universal Coordinated Time), measured in milliseconds.

sign = (sign >= 0) ? 1 : -1;
hours = (hours >= 0) ? hours : -hours;
minutes = (minutes >= 0) ? minutes : -minutes;
if ((hours > 30) || (minutes > 1800))
    throw new IllegalArgumentException(
            "The magnitude of one or both of the hours or minutes value is outside the acceptable range.");
return sign * (hours * 3600000 + minutes * 60000);