Skip to content

Instantly share code, notes, and snippets.

@scruffyfox
Created June 20, 2013 10:51
Show Gist options
  • Select an option

  • Save scruffyfox/5821823 to your computer and use it in GitHub Desktop.

Select an option

Save scruffyfox/5821823 to your computer and use it in GitHub Desktop.
Get time/date string based on user's set date/time configuration
GregorianCalendar cal = new GregorianCalendar();
GregorianCalendar todayDate = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
long startDate = todayDate.getTimeInMillis();
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(c);
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(c);
String time = "";
if (getPostDate() > startDate)
{
time = timeFormat.format(new Date(getPostDate()));
}
else
{
time = dateFormat.format(new Date(getPostDate()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment