package com.test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Date todayDate = new Date();// 取时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(todayDate);
String[] formatDate=dateStr.split("-");
int year=Integer.parseInt(formatDate[0]);
int month=Integer.parseInt(formatDate[1]);
int day=Integer.parseInt(formatDate[2]);
String halfMonthFlag = "1";//默认上半月
String fistDayStart = "";
String middleDayEnd = "";
String middleDayStart = "";
String lastDayEnd = "";
if(day>15){
halfMonthFlag = "2";//下半月
}
fistDayStart = year+"-"+(month<10?("0"+month):(month))+"-"+"01 00:00:00";
middleDayEnd = year+"-"+(month<10?("0"+month):(month))+"-"+"15 23:59:59";
middleDayStart = year+"-"+(month<10?("0"+month):(month))+"-"+"16 00:00:00";
month++;
if(month>12) { year++; month=1; }
lastDayEnd = year+"-"+(month<10?("0"+month):(month))+"-"+"01 00:00:00";
System.out.println("当前日期是(上半月or下半月):"+halfMonthFlag);
System.out.println("当前第一天开始时间:"+fistDayStart);
System.out.println("当月中间结束时间:"+middleDayEnd);
System.out.println("当月中间开始时间:"+middleDayStart);
System.out.println("当月结束时间(即下个月第一天的开始时间):"+lastDayEnd);
}
}