Here you can find the source of setTimeToZero(final Date date)
public static Date setTimeToZero(final Date date)
//package com.java2s; /*//from w w w . j a v a2s .c o m TimeUtil.java / Freenet Copyright (C) 2005-2006 The Free Network project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { /** * @return Returns the passed date with the same year/month/day but with the time set to 00:00:00.000 */ public static Date setTimeToZero(final Date date) { // We need to cut off the hour/minutes/seconds final GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(date.getTime()); // We must not use setTime(date) in case the date is not UTC. calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } }