Java Hour hourAgo()

Here you can find the source of hourAgo()

Description

Get date for hour ago from now

License

Apache License

Return

date

Declaration

public static Date hourAgo() 

Method Source Code


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

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

public class Main {
    /**// w ww  .j a  v a2  s. co m
     * Get date for hour ago from now
     *
     * @return date
     */
    public static Date hourAgo() {
        return forCalendarDiff(Calendar.HOUR, -1);
    }

    /**
     * Get date for calendar difference from current date
     *
     * @param field  difference field (Calendar.DATE, Calendar.MINUTE ... etc)
     * @param amount how much?
     * @return date for the difference
     */
    public static Date forCalendarDiff(int field, int amount) {
        GregorianCalendar gCal = new GregorianCalendar();
        gCal.add(field, amount);
        return new Date(gCal.getTimeInMillis());
    }
}

Related

  1. getTaskTrigger(int taskTriggerHour, boolean tomorrow)
  2. getTicksTill(int hour)
  3. getTicksTillHour()
  4. hour()
  5. hour()
  6. hourCompletion(boolean hourPresent, int hour, boolean minutePresent, int minute, boolean secondPresent, int second, boolean milliPresent, int milli, String choice)
  7. HourNow()
  8. Hours()
  9. hours(int hours)