Here you can find the source of getYearForWeek(final Calendar cal)
found here: http://www.odi.ch/prog/design/datetime.php
Parameter | Description |
---|---|
cal | a parameter |
public static int getYearForWeek(final Calendar cal)
//package com.java2s; /******************************************************************************* * Copyright (C) 2005, 2016 Wolfgang Schramm and Contributors * * This program 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 version 2 of the License.// www . j a v a2 s. c o m * * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *******************************************************************************/ import java.util.Calendar; public class Main { /** * found here: http://www.odi.ch/prog/design/datetime.php * * @param cal * @return */ public static int getYearForWeek(final Calendar cal) { final int year = cal.get(Calendar.YEAR); final int week = cal.get(Calendar.WEEK_OF_YEAR); final int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); if (week == 1 && dayOfMonth > 20) { return year + 1; } if (week >= 52 && dayOfMonth < 10) { return year - 1; } return year; } }