get first Day Of Half Year - Android java.util

Android examples for java.util:Day

Description

get first 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 getfirstDayOfHalfYear() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd",
                Locale.CHINA);//from  w  w w. j a  v a2  s.  co m
        Calendar cal = Calendar.getInstance();

        int month = cal.get(Calendar.MONTH);
        if (month <= 5) {
            cal.set(Calendar.MONTH, Calendar.JANUARY);
            cal.set(Calendar.DAY_OF_MONTH, 1);
        } else {
            cal.set(Calendar.MONTH, Calendar.JULY);
            cal.set(Calendar.DAY_OF_MONTH, 1);
        }
        return format.format(cal.getTime());
    }
}

Related Tutorials