get Last Day Of Half Year - Android java.util

Android examples for java.util:Day

Description

get Last Day Of Half Year

Demo Code


//package com.java2s;

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

import java.util.Locale;

public class Main {

    public static String getLastDayOfHalfYear() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);//from  w ww .ja v a2s  .  c  o m
        Calendar cal = Calendar.getInstance();

        int month = cal.get(Calendar.MONTH);
        if (month <= 5) {
            cal.set(Calendar.MONTH, Calendar.JUNE);
            cal.set(Calendar.DAY_OF_MONTH, 30);
        } else {
            cal.set(Calendar.MONTH, Calendar.DECEMBER);
            cal.set(Calendar.DAY_OF_MONTH, 31);
        }
        return format.format(cal.getTime());
    }
}

Related Tutorials