Created
February 15, 2009 12:38
-
-
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.
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
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