Here you can find the source of alignHours(int interval, Calendar timestamp)
Parameter | Description |
---|---|
interval | The number of hours in the interval to align to. |
timestamp | The calendar to align. |
public static Calendar alignHours(int interval, Calendar timestamp)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/* w w w . j av a 2 s . com*/ * Aligns the time fields to the start of given interval. * @param interval The number of hours in the interval to align to. * @param timestamp The calendar to align. * @return The calendar parameter, aligned. */ public static Calendar alignHours(int interval, Calendar timestamp) { int value = timestamp.get(Calendar.HOUR_OF_DAY); value = value - (value % interval); timestamp.set(Calendar.HOUR_OF_DAY, value); return alignHour(timestamp); } /** * Aligns the time fields to the start of the hour. * @param timestamp The calendar to align. * @return The parameter. */ public static Calendar alignHour(Calendar timestamp) { timestamp.set(Calendar.MINUTE, 0); timestamp.set(Calendar.SECOND, 0); timestamp.set(Calendar.MILLISECOND, 0); return timestamp; } }