get Start Of This Month In Milliseconds - Android java.util

Android examples for java.util:Millisecond

Description

get Start Of This Month In Milliseconds

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    public static long getStartOfThisMonthInMilli() {
        Calendar cal = initClearDayCal();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        return cal.getTimeInMillis();
    }//  w w w. j av a2  s  .  c o  m

    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