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

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

Description

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

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

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

Method Source Code

//package com.java2s;
/*/*  www . j  av  a2s  .c  o m*/
 * Kuali Coeus, a comprehensive research administration system for higher education.
 * 
 * Copyright 2005-2015 Kuali, Inc.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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());
    }
}

Related

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