Skip to content

Instantly share code, notes, and snippets.

@p3t0r
Created February 15, 2009 12:38
Show Gist options
  • Save p3t0r/64697 to your computer and use it in GitHub Desktop.
Save p3t0r/64697 to your computer and use it in GitHub Desktop.
a piece of code to reformat a date which doesn't perform well on Android devices.
private static final String TW33T0R_DATE_PATTERN = "HH:mm:ss - MMM dd";
private static final String TWITTER_DATE_PATTERN = "EEE MMM dd HH:mm:ss Z yyyy";
/**
* @param d The datestring as received from the twitter api
* @return the date formatted in tw33t0r format
*/
private static String reformatTwitterDateToTw33t0rRepresentation(final String d) {
SimpleDateFormat formatter = new SimpleDateFormat(TWITTER_DATE_PATTERN);
try {
final Date date = formatter.parse(d);
formatter = new SimpleDateFormat(TW33T0R_DATE_PATTERN);
return formatter.format(date);
} catch (final ParseException e) {
Log.w("date parsing", e.getMessage() + " will return input as result");
return d;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment