Here you can find the source of clearTime(Calendar cal)
Parameter | Description |
---|---|
cal | The calendar object to clear. |
public static void clearTime(Calendar cal)
//package com.java2s; /*// ww w. ja v a 2s . c o m * Copyright 2006 The National Library of New Zealand * * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 * * 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.Date; public class Main { /** * Clears the time component on a Calendar object. The * passed in Calendar object is updated. * @param cal The calendar object to clear. */ public static void clearTime(Calendar cal) { cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); } /** * Clears the time on a Date object. * @param dt The input date. * @return A new date with the same date, but with the time cleared. */ public static Date clearTime(Date dt) { Calendar cal = Calendar.getInstance(); cal.setTime(dt); clearTime(cal); return cal.getTime(); } }