Here you can find the source of hourAgo()
public static Date hourAgo()
//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()); } }