Java SQL Time Field clearTimeFields(java.util.Date date)

Here you can find the source of clearTimeFields(java.util.Date date)

Description

Convert the given java.util.date into a java.util.date of which all the time fields are set to 0.

License

Educational Community License

Parameter

Parameter Description
date a parameter

Declaration

public static java.util.Date clearTimeFields(java.util.Date date) 

Method Source Code

//package com.java2s;
/*//from  w w w  .j  av  a2s. com
 * Copyright 2006-2008 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    /**
     * Convert the given java.sql.date into a java.sql.date of which all the time fields are set to 0.
     *
     * @param date
     * @return
     */
    public static java.sql.Date clearTimeFields(java.sql.Date date) {
        Calendar timelessCal = new GregorianCalendar();
        timelessCal.setTime(date);
        timelessCal.set(Calendar.HOUR_OF_DAY, 0);
        timelessCal.set(Calendar.MINUTE, 0);
        timelessCal.set(Calendar.SECOND, 0);
        timelessCal.set(Calendar.MILLISECOND, 0);

        return new java.sql.Date(timelessCal.getTimeInMillis());
    }

    /**
     * Convert the given java.util.date into a java.util.date of which all the time fields are set to 0.
     *
     * @param date
     * @return
     */
    public static java.util.Date clearTimeFields(java.util.Date date) {
        Calendar timelessCal = new GregorianCalendar();
        timelessCal.setTime(date);
        timelessCal.set(Calendar.HOUR_OF_DAY, 0);
        timelessCal.set(Calendar.MINUTE, 0);
        timelessCal.set(Calendar.SECOND, 0);
        timelessCal.set(Calendar.MILLISECOND, 0);

        return new java.util.Date(timelessCal.getTimeInMillis());
    }
}

Related

  1. clearTime(final Calendar self)
  2. clearTimeCommon(final Calendar self)
  3. clearTimeFields(java.sql.Date date)
  4. getDay(long time)
  5. getHoraFormatada(Time hora, String formato)
  6. getHour(String time)
  7. getHoursAndMinutes(String dateTime)