Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    public static boolean checkToday(String date) {
        Calendar today = Calendar.getInstance();
        Calendar day = StringToCalendar(date);
        return ((today.get(Calendar.YEAR) == day.get(Calendar.YEAR))
                && (today.get(Calendar.MONTH) == day.get(Calendar.MONTH))
                && (today.get(Calendar.DAY_OF_MONTH) == day.get(Calendar.DAY_OF_MONTH)));
    }

    public static Calendar StringToCalendar(String datetime) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            calendar.setTime(simpleDateFormat.parse(datetime));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return calendar;
    }
}