Java Today isToday(Date date)

Here you can find the source of isToday(Date date)

Description

is Today

License

Apache License

Declaration

public static boolean isToday(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    /**//from  www.  jav a 2  s  .co  m
     * Default date format
     */
    public static final String DATE_FORMAT = "yyyy-MM-dd";

    public static boolean isToday(Date date) {
        if (date == null) {
            return false;
        }
        String dateAsText = toDateText(date);
        String todayAsText = toDateText(now());
        return dateAsText.equals(todayAsText);
    }

    public static String toDateText(Date date) {
        return toDateText(date, DATE_FORMAT);
    }

    public static String toDateText(Date date, String pattern) {
        if (date == null || pattern == null) {
            return null;
        }
        DateFormat dateFormat = createDateFormat(pattern);
        return dateFormat.format(date);
    }

    public static Date now() {
        return new Date();
    }

    private static DateFormat createDateFormat(String pattern) {
        return new SimpleDateFormat(pattern, Locale.SIMPLIFIED_CHINESE);
    }
}

Related

  1. isBeforeToday(Date date)
  2. isBeforeToday(Date date)
  3. isGreaterThanToday(String dateString)
  4. isToday(Date d1)
  5. isToday(Date date)
  6. isToday(Date date, TimeZone timezone)
  7. isToday(Date dateTime)
  8. isToday(final Date date)
  9. isToday(final Date date)