Java Week Day weekday(String date)

Here you can find the source of weekday(String date)

Description

weekday

License

Open Source License

Declaration

public static String weekday(String date) throws ParseException 

Method Source Code


//package com.java2s;
/*//  www . j  ava 2  s.co m
 * Copyright (C) 2006-2016 Talend Inc. - www.talend.com
 * 
 * This source code is available under agreement available at
 * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
 * 
 * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages
 * 92150 Suresnes, France
 */

import java.text.DateFormat;
import java.text.ParseException;

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

public class Main {
    public static String weekday(String date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        DateFormat dateFormat = DateFormat.getDateInstance();

        Date da = null;
        da = dateFormat.parse(date);

        calendar.setTime(da);
        int num = calendar.get(Calendar.DAY_OF_WEEK);

        if (num == 1) {
            num = 7;
        } else {
            num = num - 1;
        }

        return num + "";//$NON-NLS-1$

    }
}

Related

  1. nextWeekday(int weekday, int hour, int minute, int second)
  2. parseToEntireWeekCaption(String startDay, String pattern)
  3. plusDay(Date date, int plusWeek)
  4. toDayOfWeekInMonth(Calendar c, int dayOfWeek, int weekInMonth)
  5. weekDay(int week)