Java examples for java.util:Time
strip Time Info from Date
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static void main(String[] argv) throws Exception { Date datetime = new Date(); System.out.println(stripTimeInfo(datetime)); }/*ww w . j a v a 2 s. c o m*/ public static Date stripTimeInfo(Date datetime) { if (datetime == null) { return null; } Calendar calendar = getCalendar(); calendar.setTime(datetime); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } public static Calendar getCalendar() { return GregorianCalendar.getInstance(); } }