Skip to content

Instantly share code, notes, and snippets.

@kosiara kosiara/TweetViewUtil.kt

Last active Aug 30, 2018
What would you like to do?
Reformat Twitter date
* 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>(
dateTextView.text = parseDate(tweet.createdAt, twitterDatePattern).format(newDatePattern)
* Parse date according to a Pattern
fun parseDate(stringDate: String, pattern: String): Date = SimpleDateFormat(pattern).parse(stringDate)
* Format Date according to Pattern (SimpleDateFormat)
fun Date.format(pattern: String) : String = SimpleDateFormat(pattern).format(this)
val tweet = result!!.data
val tweetView = TweetView(componentInstance.context, tweet,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.