get Monday Of Week - Android java.util

Android examples for java.util:Day

Description

get Monday 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 getMondayOfWeek(String date) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);//from  www .j a v a  2  s . c o m
        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