import java.io.PrintStream;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TestTime {
private int weeks = 0;
private int MaxDate;
private int MaxYear;
public static void main(String[] paramArrayOfString) {
TestTime localTestTime = new TestTime();
System.out.println("获取当天日期:" + localTestTime.getNowTime("yyyy-MM-dd"));
System.out.println("获取本周一日期:" + localTestTime.getMondayOFWeek());
System.out.println("获取本周日的日期~:" + localTestTime.getCurrentWeekday());
System.out.println("获取上周一日期:" + localTestTime.getPreviousWeekday());
System.out.println("获取上周日日期:" + localTestTime.getPreviousWeekSunday());
System.out.println("获取下周一日期:" + localTestTime.getNextMonday());
System.out.println("获取下周日日期:" + localTestTime.getNextSunday());
System.out.println("获得相应周的周六的日期:" + localTestTime.getNowTime("yyyy-MM-dd"));
System.out.println("获取本月第一天日期:" + localTestTime.getFirstDayOfMonth());
System.out.println("获取本月最后一天日期:" + localTestTime.getDefaultDay());
System.out.println("获取上月第一天日期:" + localTestTime.getPreviousMonthFirst());
System.out.println("获取上月最后一天的日期:" + localTestTime.getPreviousMonthEnd());
System.out.println("获取下月第一天日期:" + localTestTime.getNextMonthFirst());
System.out.println("获取下月最后一天日期:" + localTestTime.getNextMonthEnd());
System.out.println("获取本年的第一天日期:" + localTestTime.getCurrentYearFirst());
System.out.println("获取本年最后一天日期:" + localTestTime.getCurrentYearEnd());
System.out.println("获取去年的第一天日期:" + localTestTime.getPreviousYearFirst());
System.out.println("获取去年的最后一天日期:" + localTestTime.getPreviousYearEnd());
System.out.println("获取明年第一天日期:" + localTestTime.getNextYearFirst());
System.out.println("获取明年最后一天日期:" + localTestTime.getNextYearEnd());
System.out.println("获取本季度第一天到最后一天:" + localTestTime.getThisSeasonTime(11));
System.out.println("获取两个日期之间间隔天数2008-12-1~2008-9.29:" + getTwoDay("2008-12-1", "2008-9-29")); }
public static String getTwoDay(String paramString1, String paramString2) {
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
long l = 0L;
try {
Date localDate1 = localSimpleDateFormat.parse(paramString1);
Date localDate2 = localSimpleDateFormat.parse(paramString2);
l = (localDate1.getTime() - localDate2.getTime()) / 86400000L;
} catch (Exception localException) {
return "";
} return l + "";
}
public static String getWeek(String paramString) {
Date localDate = strToDate(paramString);
Calendar localCalendar = Calendar.getInstance();
localCalendar.setTime(localDate);
return new SimpleDateFormat("EEEE").format(localCalendar.getTime());
}
public static Date strToDate(String paramString) {
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition localParsePosition = new ParsePosition(0);
Date localDate = localSimpleDateFormat.parse(paramString, localParsePosition);
return localDate;
}
public static long getDays(String paramString1, String paramString2) {
if ((paramString1 == null) || (paramString1.equals(""))) return 0L;
if ((paramString2 == null) || (paramString2.equals(""))) { return 0L; }
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date localDate1 = null; Date localDate2 = null;
try {
localDate1 = localSimpleDateFormat.parse(paramString1);
localDate2 = localSimpleDateFormat.parse(paramString2);
} catch (Exception localException) {
} long l = (localDate1.getTime() - localDate2.getTime()) / 86400000L; return l; }
public String getDefaultDay() {
String str = "";
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance();
localCalendar.set(5, 1);
localCalendar.add(2, 1);
localCalendar.add(5, -1);
str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getPreviousMonthFirst() {
String str = "";
SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.set(5, 1); localCalendar.add(2, -1);
str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getFirstDayOfMonth() { String str = ""; SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.set(5, 1); str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getCurrentWeekday() { this.weeks = 0; int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + 6); Date localDate = localGregorianCalendar.getTime();
DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getNowTime(String paramString) { Date localDate = new Date(); SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString); String str = localSimpleDateFormat.format(localDate); return str; }
private int getMondayPlus() { Calendar localCalendar = Calendar.getInstance();
int i = localCalendar.get(7) - 1; if (i == 1) { return 0; } return 1 - i; }
public String getMondayOFWeek() { this.weeks = 0; int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i); Date localDate = localGregorianCalendar.getTime();
DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getSaturday() { int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + 7 * this.weeks + 6); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getPreviousWeekSunday() { this.weeks = 0; this.weeks -= 1; int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + this.weeks); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getPreviousWeekday() { this.weeks -= 1; int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + 7 * this.weeks); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getNextMonday() { this.weeks += 1; int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + 7); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getNextSunday() { int i = getMondayPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + 7 + 6); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
private int getMonthPlus() { Calendar localCalendar = Calendar.getInstance(); int i = localCalendar.get(5); localCalendar.set(5, 1); localCalendar.roll(5, -1); this.MaxDate = localCalendar.get(5); if (i == 1) { return -this.MaxDate; } return 1 - i; }
public String getPreviousMonthEnd() { String str = ""; SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.add(2, -1); localCalendar.set(5, 1); localCalendar.roll(5, -1); str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getNextMonthFirst() { String str = ""; SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.add(2, 1); localCalendar.set(5, 1); str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getNextMonthEnd() { String str = ""; SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.add(2, 1); localCalendar.set(5, 1); localCalendar.roll(5, -1); str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getNextYearEnd() { String str = ""; SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.add(1, 1); localCalendar.set(6, 1); localCalendar.roll(6, -1); str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
public String getNextYearFirst() { String str = ""; SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar localCalendar = Calendar.getInstance(); localCalendar.add(1, 1); localCalendar.set(6, 1); str = localSimpleDateFormat.format(localCalendar.getTime()); return str; }
private int getMaxYear() { Calendar localCalendar = Calendar.getInstance(); localCalendar.set(6, 1); localCalendar.roll(6, -1); int i = localCalendar.get(6); return i; }
private int getYearPlus() { Calendar localCalendar = Calendar.getInstance(); int i = localCalendar.get(6); localCalendar.set(6, 1); localCalendar.roll(6, -1); int j = localCalendar.get(6); if (i == 1) { return -j; } return 1 - i; }
public String getCurrentYearFirst() { int i = getYearPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); return str; }
public String getCurrentYearEnd() { Date localDate = new Date(); SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy"); String str = localSimpleDateFormat.format(localDate); return str + "-12-31"; }
public String getPreviousYearFirst() { Date localDate = new Date(); SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy"); String str = localSimpleDateFormat.format(localDate); int i = Integer.parseInt(str); i--; return i + "-1-1"; }
public String getPreviousYearEnd() { this.weeks -= 1; int i = getYearPlus(); GregorianCalendar localGregorianCalendar = new GregorianCalendar(); localGregorianCalendar.add(5, i + this.MaxYear * this.weeks + (this.MaxYear - 1)); Date localDate = localGregorianCalendar.getTime(); DateFormat localDateFormat = DateFormat.getDateInstance(); String str = localDateFormat.format(localDate); getThisSeasonTime(11); return str; }
public String getThisSeasonTime(int paramInt) { int[][] arrayOfInt = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }; int i = 1; if ((paramInt >= 1) && (paramInt <= 3)) { i = 1; } if ((paramInt >= 4) && (paramInt <= 6)) { i = 2; } if ((paramInt >= 7) && (paramInt <= 9)) { i = 3; } if ((paramInt >= 10) && (paramInt <= 12)) { i = 4; } int j = arrayOfInt[(i - 1)][0]; int k = arrayOfInt[(i - 1)][2];
Date localDate = new Date(); SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy"); String str1 = localSimpleDateFormat.format(localDate); int m = Integer.parseInt(str1);
int n = 1; int i1 = getLastDayOfMonth(m, k); String str2 = m + "-" + j + "-" + n + ";" + m + "-" + k + "-" + i1; return str2; }
private int getLastDayOfMonth(int paramInt1, int paramInt2) { if ((paramInt2 == 1) || (paramInt2 == 3) || (paramInt2 == 5) || (paramInt2 == 7) || (paramInt2 == 8) || (paramInt2 == 10) || (paramInt2 == 12)) { return 31; } if ((paramInt2 == 4) || (paramInt2 == 6) || (paramInt2 == 9) || (paramInt2 == 11)) { return 30; } if (paramInt2 == 2) { if (isLeapYear(paramInt1)) { return 29; } return 28; }
return 0; }
public boolean isLeapYear(int paramInt) { return ((paramInt % 4 == 0) && (paramInt % 100 != 0)) || (paramInt % 400 == 0); } }