Java Week Day getMondayAfter(Date date)

Here you can find the source of getMondayAfter(Date date)

Description

get Monday After

License

Open Source License

Parameter

Parameter Description
date Any date

Return

The date that is the Monday after the date. If the provided date is Monday then it will be returned as-is.

Declaration

public static Date getMondayAfter(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Boeing./* ww  w . jav a 2 s. c o  m*/
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * @param date Any date
     * @return The date that is the Monday after the date. If the provided date is Monday then it will be returned as-is.
     */
    public static Date getMondayAfter(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            cal.add(Calendar.DATE, 1);
        }
        return cal.getTime();
    }

    public static String get(Date date) {
        if (date == null) {
            return "";
        }
        return DateFormat.getDateInstance().format(date);
    }

    public static String get(Date date, String pattern) {
        return get(date, new SimpleDateFormat(pattern));
    }

    public static String get(Date date, DateFormat dateFormat) {
        if (date == null) {
            return "";
        }
        String result = dateFormat.format(date);
        return result;
    }
}

Related

  1. getLastWeekDay(int weekDay)
  2. getLastWeekMs()
  3. getMon()
  4. getMonday(String date)
  5. getMonday(String date, int weekDay)
  6. getMondayOfThisWeek()
  7. getNextDayOfweek()
  8. getPreDay()
  9. getPreviousDay(long date, int startOfWeek)