Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    public static void showRounding(Calendar b) {
        System.out.println("-----------------------");
        System.out.println(b.getTime() + " is start point");
        System.out.println(toNextWholeHour(b).getTime() + " is next whole hour");
        System.out.println(toNextWholeMinute(b).getTime() + " is next whole minute");
        /*        System.out.println(toNearestWholeMinute(b).getTime() + " is nearest whole minute");
         System.out.println(toNearestWholeHour(b).getTime() + " is nearest whole hour");*/
    }

    static Calendar toNextWholeHour(Calendar d) {
        Calendar c = new GregorianCalendar();
        c.setTime(d.getTime());
        c.add(Calendar.HOUR, 1);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        return c;
    }

    static Calendar toNextWholeMinute(Calendar d) {
        Calendar c = new GregorianCalendar();
        c.setTime(d.getTime());
        c.add(Calendar.MINUTE, 1);
        c.set(Calendar.SECOND, 0);
        return c;
    }
}