Skip to content

Instantly share code, notes, and snippets.

@MizzleDK
Created September 15, 2015 19:33
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 MizzleDK/f772a1aed61a842954d2 to your computer and use it in GitHub Desktop.
Save MizzleDK/f772a1aed61a842954d2 to your computer and use it in GitHub Desktop.
Examples with DateUtils.formatDateRange()
long lastYear = 1407869895000L; // August 12, 2014, 8:58PM
long before = 1439405895000L; // August 12, 2015, 8:58PM
long now = 1442343495000L; // September 15, 2015, 8:58PM
// August 12 – September 15 (default)
DateUtils.formatDateRange(this, before, now, 0);
// August 12, 8:58PM – September 15, 8:58PM (with time)
DateUtils.formatDateRange(this, before, now, DateUtils.FORMAT_SHOW_TIME);
// Aug 12 – Sep 15 (short month name, deprecated as it's not useful for all locales)
DateUtils.formatDateRange(this, before, now, DateUtils.FORMAT_ABBREV_MONTH);
// August 12 – September 15, 2015 (same year)
DateUtils.formatDateRange(this, before, now, DateUtils.FORMAT_SHOW_YEAR);
// August 12, 2014 – September 15, 2015 (different years)
DateUtils.formatDateRange(this, lastYear, now, DateUtils.FORMAT_SHOW_YEAR);
// Aug 12, 2015, 8:58 PM – Sep 15, 2015, 8:58 PM (everything above in conjunction)
DateUtils.formatDateRange(this, before, now, DateUtils.FORMAT_SHOW_TIME|
DateUtils.FORMAT_ABBREV_MONTH|DateUtils.FORMAT_SHOW_YEAR);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment