get Last Month Start In Milliseconds - Android java.util

Android examples for java.util:Millisecond

Description

get Last Month Start In Milliseconds

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    public static long getLastMonthStartInMilli() {
        Calendar cal = initClearDayCal();
        cal.add(Calendar.MONTH, -1);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        return cal.getTimeInMillis();
    }/*from   w w  w  .j  a va2  s  .com*/

    private static Calendar initClearDayCal() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
        cal.clear(Calendar.MINUTE);
        cal.clear(Calendar.SECOND);
        cal.clear(Calendar.MILLISECOND);

        return cal;
    }
}

Related Tutorials