Here you can find the source of getHourOfWeek(Date dateIn)
Parameter | Description |
---|---|
dateIn | the date to extract the hour of the week. |
Parameter | Description |
---|---|
IllegalArgumentException | if the parameter dateIn is null. |
public static int getHourOfWeek(Date dateIn)
//package com.java2s; /*/*from ww w. j a v a2 s . c o m*/ * #%L * org.bml * %% * Copyright (C) 2006 - 2014 Brian M. Lima * %% * This file is part of ORG.BML. * * ORG.BML 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 3 of the License, or * (at your option) any later version. * * ORG.BML 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with ORG.BML. If not, see <http://www.gnu.org/licenses/>. * #L% */ import java.util.Calendar; import java.util.Date; public class Main { /**Returns the hour of the week in the range of 1 to 168. 1 being the first hour of * Sunday, 168 being the last hour of Saturday. * * @param dateIn the date to extract the hour of the week. * @return an integer in the range of 1 to 168. 1 being the first hour of * Sunday. * @throws IllegalArgumentException if the parameter dateIn is null. */ public static int getHourOfWeek(Date dateIn) { if (dateIn == null) { throw new IllegalArgumentException("Can not operate on a null Date object."); } Calendar cal = Calendar.getInstance(); cal.setTime(dateIn); return ((cal.get(Calendar.DAY_OF_WEEK) - 1) * 24) + cal.get(Calendar.HOUR_OF_DAY); } }