Last active
August 20, 2019 19:14
-
-
Save wszdwp/1a222a36166df7511d138ac69812f366 to your computer and use it in GitHub Desktop.
Some date time related gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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