Java Today isToday(String depDateTime)

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

Description

Is a dateTime today

License

Apache License

Parameter

Parameter Description
dateTimeString in format 2012-10-15T08:17:00

Return

true if today

Declaration

public static boolean isToday(String depDateTime) 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    /**/*  w ww .  ja  va  2  s  .  c  o m*/
     * Is a dateTime today
     * @param dateTimeString in format 2012-10-15T08:17:00
     * @return true if today
     * */
    public static boolean isToday(String depDateTime) {
        boolean isToday = false;
        Calendar depDate = parseCalendarString(depDateTime);
        int depDay = depDate.get(Calendar.DAY_OF_MONTH);
        Calendar now = getTimeNow();
        int nowDay = now.get(Calendar.DAY_OF_MONTH);
        if (depDay == nowDay) {
            isToday = true;
        }
        return isToday;
    }

    /**
     *Converts a dateTimeString and makes a Calendar object
     * @param dateTimeString in format 2012-10-15T08:17:00
     * @return Calendar object
     * */
    public static Calendar parseCalendarString(String dateTimeString) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ss");
        Date date = null;
        try {
            date = dateFormat.parse(dateTimeString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm"));
        cal.setTime(date);
        return cal;
    }

    /**
     *Returns now
     * @return Calendar object
     * */
    public static Calendar getTimeNow() {
        Calendar now = Calendar.getInstance();
        now.setTime(new Date());
        return now;
    }
}

Related

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