Last active
August 29, 2015 13:58
-
-
Save BenoitDuffez/9996012 to your computer and use it in GitHub Desktop.
This file contains 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
public static String getDeltaDateText(Context context, Calendar date) { | |
final String formattedDate; | |
if (date != null && date.getTimeInMillis() > 10000) { | |
long delta = (new GregorianCalendar().getTimeInMillis() - date.getTimeInMillis()) / 1000; | |
if (delta < 60) { | |
formattedDate = context.getString(R.string.time_delay_moments); | |
} else if (delta < 3600) { | |
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_minutes), (int) (delta / 60)); | |
} else if (delta < 3600 * 24) { | |
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_hours), (int) (delta / 3600)); | |
} else if (delta < 3600 * 24 * 30) { | |
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_days), (int) (delta / (3600 * 24))); | |
} else if (delta < 3600 * 24 * 365) { | |
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_months), (int) (delta / (3600 * 24 * 30))); | |
} else { | |
formattedDate = MessageFormat.format(context.getString(R.string.time_delay_years), (int) (delta / (3600 * 24 * 365))); | |
} | |
} else { | |
formattedDate = ""; | |
} | |
return formattedDate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment