Java tutorial
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static boolean isToday(Date date) { Date currentDate = new Date(); Date firstTimeOfDate = firstTimeOfDate(currentDate); float currentSecond = secondFromMilisecond(firstTimeOfDate.getTime()); float actuallySecond = secondFromMilisecond(date.getTime()); float delta = actuallySecond - currentSecond; if (delta >= 0 && delta < 60 * 60 * 24 * 1) { return true; } return false; /* * comment Tan's Code to test Today boolean isToday = false; Date * currentTime = new Date(); Calendar cal = Calendar.getInstance(); * cal.setTime(currentTime); * * Calendar calCurrentView = Calendar.getInstance(); * calCurrentView.setTime(date); * * isToday = (cal.get(Calendar.YEAR) == * calCurrentView.get(Calendar.YEAR)) && (cal.get(Calendar.MONTH) == * calCurrentView .get(Calendar.MONTH)) && * (cal.get(Calendar.DAY_OF_MONTH) == calCurrentView * .get(Calendar.DAY_OF_MONTH)); return isToday; */ } public static Date firstTimeOfDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date dateBegin = new Date(); dateBegin.setTime(calendar.getTimeInMillis()); return dateBegin; } public static float secondFromMilisecond(float milisecond) { return milisecond / 1000; } }