Calculates the number of days the are before the start of the given calendar object (given month) - Android java.util

Android examples for java.util:Month

Description

Calculates the number of days the are before the start of the given calendar object (given month)

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    /**//w  ww . j a va2s .  c  o  m
     * Calculates the number of days the are before the start of the given calendar object (given month)
     * 
     * @param a_calendar -> given month
     * @return l_result -> the number of days
     */
    public static int getDaysAfterStartOfWeek(Calendar a_calendar) {
        int l_result = -1;
        Calendar l_tempCal = Calendar.getInstance();
        l_tempCal.setTimeInMillis(a_calendar.getTimeInMillis());
        l_tempCal.set(Calendar.DAY_OF_MONTH, 1);
        int l_day = l_tempCal.get(Calendar.DAY_OF_WEEK);

        switch (l_day) {
        case Calendar.MONDAY:
            l_result = 0;
            break;
        case Calendar.TUESDAY:
            l_result = 1;
            break;
        case Calendar.WEDNESDAY:
            l_result = 2;
            break;
        case Calendar.THURSDAY:
            l_result = 3;
            break;
        case Calendar.FRIDAY:
            l_result = 4;
            break;
        case Calendar.SATURDAY:
            l_result = 5;
            break;
        case Calendar.SUNDAY:
            l_result = 6;
            break;
        }
        return l_result;
    }
}

Related Tutorials