Here you can find the source of isToday(Date d1)
Parameter | Description |
---|---|
d1 | non-null date |
public static boolean isToday(Date d1)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**// ww w .j av a 2 s .com * test a date represents todays date * @param d1 non-null date * @return as above */ public static boolean isToday(Date d1) { return sameDay(d1, new Date()); } /** * test two dates have the same day * @param d1 non-null date * @param d2 non-null date * @return as above */ @SuppressWarnings(value = "deprecated") public static boolean sameDay(Date d1, Date d2) { if (d1.getYear() != d2.getYear()) return false; if (d1.getMonth() != d2.getMonth()) return false; if (d1.getDay() != d2.getDay()) return false; return true; } public static int getYear(Date date) { GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance(); long time = date.getTime(); calendar.setTimeInMillis(time); return calendar.get(calendar.YEAR); } /** * @param date Date * @return int month number 0-based */ public static int getMonth(Date date) { GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance(); long time = date.getTime(); calendar.setTimeInMillis(time); return calendar.get(calendar.MONTH); } }