Java Today isToday(String sdate)

Here you can find the source of isToday(String sdate)

Description

is Today

License

LGPL

Declaration

public static boolean isToday(String sdate) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private final static SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private final static SimpleDateFormat dateFormater2 = new SimpleDateFormat("yyyy-MM-dd");

    public static boolean isToday(String sdate) {
        boolean b = false;
        Date time = toDate(sdate);
        Date today = new Date();
        if (time != null) {
            String nowDate = dateFormater2.format(today);
            String timeDate = dateFormater2.format(time);
            if (nowDate.equals(timeDate)) {
                b = true;/*from   w  ww .  j a v  a2s  .c o  m*/
            }
        }
        return b;
    }

    public static Date toDate(String sdate) {
        try {
            return dateFormater.parse(sdate);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. isToday(int dateInt)
  2. isToDay(long millis)
  3. isToday(long milliseconds)
  4. isToday(long timestamp)
  5. isToday(String depDateTime)
  6. isToday(String sdate)
  7. parseToday(String s)
  8. plusDaysToday(int days)
  9. sameTimeToday(Date time)