Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

import android.util.Log;

public class Main {
    public static boolean isPastMonth(Date date) {
        Date currentDate = new Date();
        Date firstTimeOfMonth = firstTimeOfMonth(currentDate);

        float currentSecond = secondFromMilisecond(firstTimeOfMonth.getTime());
        float actuallySecond = secondFromMilisecond(date.getTime());
        float delta = actuallySecond - currentSecond;
        Log.v("Time currentDate", "" + currentDate);
        Log.v("Time currentSecond", "" + firstTimeOfMonth);
        Log.v("Time actuallySecond", "" + date);
        Log.v("Time delta", "" + delta);
        if (delta > 0 && delta <= 60 * 60 * 24 * 30) {
            return true;
        }
        return false;
    }

    public static Date firstTimeOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(date.getTime());

        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);

        Date dateBegin = new Date();
        dateBegin.setTime(calendar.getTimeInMillis());
        return dateBegin;
    }

    public static float secondFromMilisecond(float milisecond) {
        return milisecond / 1000;

    }
}