get Last Hour Today - Java java.util

Java examples for java.util:Hour

Description

get Last Hour Today

Demo Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getLastHourToday());
    }/*from   w w w. j ava 2s.co m*/

    public static Calendar getLastHourToday() {
        return getLastHourDay(new Date());
    }

    public static Calendar getLastHourDay(Date date) {
        Calendar calendar = GregorianCalendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 00);
        return calendar;
    }
}

Related Tutorials