Table of Contents ⇒ Java Algorithm Library-Artery-Sample
package jp.avaj.lib.algo;
import java.util.Calendar;
import jp.avaj.lib.test.L;
/**
*Round up and down the time
*
*・ Date,Calendar,For long you can
*・ Today's 0:00 and tomorrow's 0:00.
*・ Truncate minutes / seconds, round up minutes / seconds
*
*/
public class Q05_01 {
public static void main(String[] args) {
L.p("Today at 0:00");
{
Calendar cal = ArDateUtil.getCalendar();
L.p(ArDateUtil.toString(cal));
cal = ArDateUtil.downTo0H0M0S(cal);
L.p(ArDateUtil.toString(cal));
}
L.p("Tomorrow at 0:00");
{
Calendar cal = ArDateUtil.getCalendar();
L.p(ArDateUtil.toString(cal));
cal = ArDateUtil.upTo0H0M0S(cal);
L.p(ArDateUtil.toString(cal));
}
L.p("Truncate minutes and seconds");
{
Calendar cal = ArDateUtil.getCalendar();
L.p(ArDateUtil.toString(cal));
cal = ArDateUtil.downTo0M0S(cal);
L.p(ArDateUtil.toString(cal));
}
L.p("Round up minutes and seconds");
{
Calendar cal = ArDateUtil.getCalendar();
L.p(ArDateUtil.toString(cal));
cal = ArDateUtil.upTo0M0S(cal);
L.p(ArDateUtil.toString(cal));
}
}
}
The result is as follows.
result.txt
Today at 0:00
2019/10/10 14:09:47
2019/10/10 00:00:00
Tomorrow at 0:00
2019/10/10 14:09:47
2019/10/11 00:00:00
Truncate minutes and seconds
2019/10/10 14:09:47
2019/10/10 14:00:00
Round up minutes and seconds
2019/10/10 14:09:47
2019/10/10 15:00:00
Recommended Posts