Here you can find the source of translateToDayNumber(int y, int m, int d)
Parameter | Description |
---|---|
y | a parameter |
m | Month number, 1=Jan, 2=Feb, ..., 12=Dec |
d | a parameter |
public static int translateToDayNumber(int y, int m, int d)
//package com.java2s; /*//from w w w .j a v a2 s . c o m Copyright 2005-2015, Olivier PETRUCCI. This file is part of Areca. Areca is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Areca 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 Areca; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.util.Calendar; import java.util.GregorianCalendar; public class Main { private static int ZERO_YEAR = 2000; private static int[] CUMUL_DAYS_PER_YEAR = { 0, 366, 731, 1096, 1461, 1827, 2192, 2557, 2922, 3288, 3653, 4018, 4383, 4749, 5114, 5479, 5844, 6210, 6575, 6940, 7305, 7671, 8036, 8401, 8766, 9132, 9497, 9862, 10227 }; /** * * @param y * @param m Month number, 1=Jan, 2=Feb, ..., 12=Dec * @param d * @return */ public static int translateToDayNumber(int y, int m, int d) { Calendar cal = new GregorianCalendar(y, m - 1, d); return translateToDayNumber(cal); } /** * Translate the calendar to a number of days since 01/01/2000 */ public static int translateToDayNumber(Calendar cal) { if (cal == null) { return 0; } else { int y = cal.get(cal.YEAR) - ZERO_YEAR; int nbD = CUMUL_DAYS_PER_YEAR[y]; nbD += cal.get(Calendar.DAY_OF_YEAR) - 1; return nbD; } } }