get Last Week Start In Milliseconds - Android java.util

Android examples for java.util:Millisecond

Description

get Last Week Start In Milliseconds

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    private static final long dayInMilli = 86400000;

    public static long getLastWeekStartInMilli() {
        return getStartOfThisWeekInMilli() - (dayInMilli * 7);
    }/*from   w ww . j  a va 2 s .  c om*/

    public static long getStartOfThisWeekInMilli() {
        Calendar cal = initClearDayCal();
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        return cal.getTimeInMillis();
    }

    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