Skip to content

Instantly share code, notes, and snippets.

@wszdwp
Last active August 20, 2019 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wszdwp/1a222a36166df7511d138ac69812f366 to your computer and use it in GitHub Desktop.
Save wszdwp/1a222a36166df7511d138ac69812f366 to your computer and use it in GitHub Desktop.
Some date time related gists
// Check leap year
public boolean isLeapYear(int year) {
boolean leapYear = false;
if (year % 4 == 0) {
if (year % 100 == 0) {
if ( year % 400 == 0) {
leapYear = true;
}
} else {
leapYear = true;
}
}
return leapYear;
}
public static String getHistoryTimeStamp(int historyKeepDays) {
final String HISTORY_DATETIME_FORMMAT = "yyyyMMdd.HH:mm:ss.SSSZ";
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -historyKeepDays);
DateFormat dateFormat = new SimpleDateFormat(HISTORY_DATETIME_FORMMAT, Locale.US);
return dateFormat.format(cal.getTime());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment