Android Date Compare isDateNew(String YearMonthDayHourMinuteSeconds)

Here you can find the source of isDateNew(String YearMonthDayHourMinuteSeconds)

Description

is Date New

Declaration

@SuppressLint("SimpleDateFormat")
    public static boolean isDateNew(String YearMonthDayHourMinuteSeconds) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.annotation.SuppressLint;

public class Main {
    @SuppressLint("SimpleDateFormat")
    public static boolean isDateNew(String YearMonthDayHourMinuteSeconds) {
        boolean flag = false;

        int numOfDays = -14;

        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, numOfDays);
        Date fourteenDaysAgo = cal.getTime();

        String expectedPattern = "yyyy-MM-dd HH:mm:ss";

        SimpleDateFormat formatter = new SimpleDateFormat(expectedPattern);
        Date date;/*  w w  w  . j  a  va 2 s  . c  o  m*/
        try {
            date = formatter.parse(YearMonthDayHourMinuteSeconds);
            if (date.after(fourteenDaysAgo) || date.equals(fourteenDaysAgo)) {
                flag = true;
            } else {
                flag = false;
            }

        } catch (Exception e) {
            flag = false;
        }

        return flag;
    }
}

Related

  1. needsMidnightCountdown()
  2. dateDiffer(Date date1, Date date2)
  3. compare(Date date1, Date date2)
  4. compare(String date0, String date1, String format)
  5. isDateTimeAfter(String startDate, String startTime, String endDate, String endTime)
  6. isSameDay(Date d1, Date d2)
  7. isSameDay(Date date1, Date date2)