Here you can find the source of absoluteDay(Calendar cal, boolean use1904windowing)
Parameter | Description |
---|---|
cal | the Calendar |
protected static int absoluteDay(Calendar cal, boolean use1904windowing)
//package com.java2s; /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at /* w w w . j av a 2s. c o m*/ http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ import java.util.Calendar; public class Main { /** * Given a Calendar, return the number of days since 1900/12/31. * * @return days number of days since 1900/12/31 * @param cal the Calendar * @exception IllegalArgumentException if date is invalid */ protected static int absoluteDay(Calendar cal, boolean use1904windowing) { //20110402, henrichen@zkoss.org: could be 1989/12/31 //return cal.get(Calendar.DAY_OF_YEAR) // + daysInPriorYears(cal.get(Calendar.YEAR), use1904windowing); final int minY = use1904windowing ? 1903 : 1899; final int year = cal.get(Calendar.YEAR); return year == minY ? 0 : cal.get(Calendar.DAY_OF_YEAR) + daysInPriorYears(cal.get(Calendar.YEAR), use1904windowing); } /** * Return the number of days in prior years since 1900 * * @return days number of days in years prior to yr. * @param yr a year (1899 <= yr < 4000) * @param use1904windowing * @exception IllegalArgumentException if year is outside of range. */ private static int daysInPriorYears(int yr, boolean use1904windowing) { if ((!use1904windowing && yr < 1900) || (use1904windowing && yr < 1900)) { throw new IllegalArgumentException("'year' must be 1900 or greater"); } int yr1 = yr - 1; int leapDays = yr1 / 4 // plus julian leap days in prior years - yr1 / 100 // minus prior century years + yr1 / 400 // plus years divisible by 400 - 460; // leap days in previous 1900 years return 365 * (yr - (use1904windowing ? 1904 : 1900)) + leapDays; } }