Java Calendar Hour truncateHour(Calendar c)

Here you can find the source of truncateHour(Calendar c)

Description

truncate Hour

License

Apache License

Declaration

public static Calendar truncateHour(Calendar c) 

Method Source Code

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

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static Calendar truncateHour(Calendar c) {
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c;
    }//from w w  w .jav a  2 s  . co m

    public static Date truncateHour(Date d) {
        return toDate(truncateHour(toCalendar(d)));
    }

    public static Date toDate(Calendar calendar) {
        return calendar.getTime();
    }

    public static Date toDate(long millis) {
        return new Date(millis);
    }

    public static Calendar toCalendar(Date date) {
        Calendar c = new GregorianCalendar();
        c.setTime(date);
        return c;
    }

    public static Calendar toCalendar(long millis) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(new Date(millis));
        return cal;
    }
}

Related

  1. setDateToZeroHour(Calendar calendar)
  2. setHourMinSecAsNull(Calendar calendar)
  3. setHours(int i, Calendar calendar)
  4. setMinHour(Calendar gc)
  5. toMinHours(Calendar calendar)
  6. truncateToHour(Calendar cal)