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();// 取時(shí)間
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";//默認(rèn)上半月
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("當(dāng)前日期是(上半月or下半月):"+halfMonthFlag);
System.out.println("當(dāng)前第一天開始時(shí)間:"+fistDayStart);
System.out.println("當(dāng)月中間結(jié)束時(shí)間:"+middleDayEnd);
System.out.println("當(dāng)月中間開始時(shí)間:"+middleDayStart);
System.out.println("當(dāng)月結(jié)束時(shí)間(即下個(gè)月第一天的開始時(shí)間):"+lastDayEnd);
}
}