get Start Of Next Week - Java java.util

Java examples for java.util:Week

Description

get Start Of Next Week

Demo Code

/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies and others.
 * 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://from  w  w w.  j av a 2 s  .  c  o  m
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/
//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getStartOfNextWeek());
    }

    private static int startDay = Calendar.MONDAY;

    public static Calendar getStartOfNextWeek() {
        Calendar cal = getCalendar();
        snapNextWorkWeek(cal);
        return snapStartOfWorkWeek(cal);
    }

    public static Calendar getCalendar() {
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(startDay);
        cal.getTime();
        return cal;
    }

    public static Calendar snapNextWorkWeek(Calendar calendar) {
        calendar.add(Calendar.WEEK_OF_MONTH, 1);
        snapStartOfWorkWeek(calendar);
        return calendar;
    }

    public static Calendar snapStartOfWorkWeek(Calendar cal) {
        cal.set(Calendar.DAY_OF_WEEK, startDay);
        snapStartOfDay(cal);
        return cal;
    }

    public static Calendar snapStartOfDay(Calendar cal) {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.getTime();
        return cal;
    }
}

Related Tutorials