Last active
August 30, 2018 19:09
-
-
Save kosiara/97934d7cf2a15d9d0993a4e4fae912da to your computer and use it in GitHub Desktop.
Reformat Twitter date
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
/** | |
* Reformat Twitter date to a new pattern | |
*/ | |
fun TweetView.reformatDate(newDatePattern: String) { | |
val twitterDatePattern = "EEE MMM dd HH:mm:ss Z yyyy" // Mon Apr 21 04:08:37 +0000 2018 | |
val dateTextView = findViewById<AppCompatTextView>(R.id.tw__tweet_timestamp) | |
dateTextView.text = parseDate(tweet.createdAt, twitterDatePattern).format(newDatePattern) | |
} | |
/** | |
* Parse date according to a Pattern | |
*/ | |
@SuppressLint("SimpleDateFormat") | |
fun parseDate(stringDate: String, pattern: String): Date = SimpleDateFormat(pattern).parse(stringDate) | |
/** | |
* Format Date according to Pattern (SimpleDateFormat) | |
*/ | |
@SuppressLint("SimpleDateFormat") | |
fun Date.format(pattern: String) : String = SimpleDateFormat(pattern).format(this) |
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
val tweet = result!!.data | |
val tweetView = TweetView(componentInstance.context, tweet, R.style.CustomTwitterStyle) | |
tweetView.reformatDate("HH:mm:ss") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment