Java Calendar Day getDayOfPeriod(Calendar cal, long timems)

Here you can find the source of getDayOfPeriod(Calendar cal, long timems)

Description

get Day Of Period

License

Open Source License

Declaration

private static int getDayOfPeriod(Calendar cal, long timems) 

Method Source Code

//package com.java2s;
/*// w  w w  .  ja  v a 2  s .c  o  m
 * NOTE: This copyright does *not* cover user programs that use HQ
 * program services by normal system calls through the application
 * program interfaces provided as part of the Hyperic Plug-in Development
 * Kit or the Hyperic Client Development Kit - this is merely considered
 * normal use of the program, and does *not* fall under the heading of
 * "derived work".
 * 
 * Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
 * This file is part of HQ.
 * 
 * HQ is free software; you can redistribute it and/or modify
 * it under the terms version 2 of the GNU General Public License as
 * published by the Free Software Foundation. This program is distributed
 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 */

import java.util.Calendar;

public class Main {
    private static Calendar _baseCal = Calendar.getInstance();

    private static int getDayOfPeriod(Calendar cal, long timems) {
        int rtn = 0;
        cal.clear();
        cal.setTime(new java.util.Date(timems));
        Calendar currCal = Calendar.getInstance();
        currCal.setTime(new java.util.Date(timems));
        while (cal.get(Calendar.YEAR) >= _baseCal.get(Calendar.YEAR)) {
            if (cal.get(Calendar.YEAR) == currCal.get(Calendar.YEAR)) {
                rtn += currCal.get(Calendar.DAY_OF_YEAR);
            } else {
                rtn += cal.get(Calendar.DAY_OF_YEAR);
            }

            cal.add(Calendar.YEAR, -1);
            cal.set(Calendar.MONTH, 11);
            cal.set(Calendar.DAY_OF_MONTH, 31);
            cal.set(Calendar.HOUR_OF_DAY, 23);
            cal.set(Calendar.MINUTE, 0);
        }
        return rtn;
    }
}

Related

  1. getDay(Calendar cal)
  2. getDay(Calendar calendar)
  3. getDay(Calendar calendar)
  4. getDayEndCalendar(Calendar cal)
  5. getDayName(Calendar cal)
  6. getDaysFromThen(Calendar aDate)
  7. getDayStr(Calendar cal)
  8. getDayString(Calendar cal1)
  9. getDayStringByCalendar(Calendar calendar)