get First Day Of Month - Android java.util

Android examples for java.util:Month

Description

get First Day Of Month

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 getFirstDayOfMonth(String date)
            throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);//from  w w  w.  j a va  2  s  . com
        Calendar cal = Calendar.getInstance();

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

Related Tutorials