Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    /**
     * Is a dateTime after tomorrow
     * @param dateTimeString in format 2012-10-15T08:17:00
     * @return true if not today or tomorrow
     * */
    public static String isAfterTomorrow(String dateTime) {
        Calendar depDate = parseCalendarString(dateTime);
        int month = depDate.get(Calendar.MONTH) + 1;
        int day = depDate.get(Calendar.DAY_OF_MONTH);
        return day + "/" + month;
    }

    /**
     *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;
    }
}