Java Day of Week getWeekday(Date d)

Here you can find the source of getWeekday(Date d)

Description

determines the day of the week

License

Open Source License

Parameter

Parameter Description
d a parameter

Return

int with the the day of the week (sunday=1)

Declaration

public static int getWeekday(Date d) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  ww  w.j  a  va2  s  .  com
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * determines the day of the week
     * 
     * @param d
     * @return int with the the day of the week (sunday=1)
     */
    public static int getWeekday(Date d) {
        if (d == null) {
            return -1;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        int w = cal.get(Calendar.DAY_OF_WEEK);
        return w;
    }
}

Related

  1. getWeekBegin(Date date)
  2. getWeekCategory(final Date date)
  3. getWeekChineseIndex(Date curDate)
  4. getWeekDate(String date)
  5. getWeekDateList(Date today, int index)
  6. getWeekDay(Date d)
  7. getWeekDay(Date date)
  8. getWeekDay(Date date)
  9. getWeekDay(Date date)