day Floor - Java java.util

Java examples for java.util:Day

Description

day Floor

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar calendar = Calendar.getInstance();
        dayFloor(calendar);//from  w  w w.  j a va2s.co  m
    }

    public static void dayFloor(Calendar calendar) {
        hourFloor(calendar);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
    }

    public static void hourFloor(Calendar calendar) {
        minuteFloor(calendar);
        calendar.set(Calendar.MINUTE, 0);
    }

    public static void hourFloor(Calendar calendar, int number) {
        minuteFloor(calendar);
        calendar.set(Calendar.MINUTE, 0);
        if (number > 1) {
            int hours = calendar.get(Calendar.HOUR);
            calendar.set(Calendar.HOUR, (hours / number) * number);
        }
    }

    public static void minuteFloor(Calendar calendar) {
        secondFloor(calendar);
        calendar.set(Calendar.SECOND, 0);
    }

    public static void minuteFloor(Calendar calendar, int number) {
        secondFloor(calendar);
        calendar.set(Calendar.SECOND, 0);
        if (number > 1) {
            int minutes = calendar.get(Calendar.SECOND);
            calendar.set(Calendar.SECOND, (minutes / number) * number);
        }
    }

    public static void secondFloor(Calendar calendar) {
        calendar.set(Calendar.MILLISECOND, 0);
    }
}

Related Tutorials