get Sunday Of Week - Android java.util

Android examples for java.util:Day

Description

get Sunday Of Week

Demo Code


//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.util.Locale;

public class Main {

    public static String getSundayOfWeek(String date) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);/*from   www. j a v  a  2s. c om*/
        Calendar cal = Calendar.getInstance();

        String monday = getMondayOfWeek(date);
        cal.setTime(format.parse(monday));
        cal.add(Calendar.DAY_OF_WEEK, 6);
        return format.format(cal.getTime());
    }

    public static String getMondayOfWeek(String date) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);
        Calendar cal = Calendar.getInstance();

        if (date != null) {
            cal.setTime(format.parse(date));
        }
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        return format.format(cal.getTime());
    }
}

Related Tutorials