Created
July 20, 2016 20:06
-
-
Save pedrolaranjeiro/92fe6f3d4dda1551da36dd867edee949 to your computer and use it in GitHub Desktop.
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
public String getTimestamp() { | |
DateTime post = new DateTime(1468973396572); | |
DateTime now = new DateTime(); | |
Period period = new Period(post, now); | |
PeriodFormatter formatter; | |
if(period.getYears() != 0){ | |
formatter = new PeriodFormatterBuilder().appendYears().appendSuffix("Y").printZeroNever().toFormatter(); | |
}else if(period.getMonths() !=0){ | |
formatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("M").printZeroNever().toFormatter(); | |
}else if(period.getWeeks() !=0){ | |
formatter = new PeriodFormatterBuilder().appendWeeks().appendSuffix("w").printZeroNever().toFormatter(); | |
}else if(period.getDays() !=0){ | |
formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d").printZeroNever().toFormatter(); | |
}else if(period.getHours() !=0){ | |
formatter = new PeriodFormatterBuilder().appendHours().appendSuffix("h").printZeroNever().toFormatter(); | |
}else if(period.getMinutes() !=0){ | |
formatter = new PeriodFormatterBuilder().appendMinutes().appendSuffix("m").printZeroNever().toFormatter(); | |
}else{ | |
formatter = new PeriodFormatterBuilder().appendSeconds().appendSuffix("s").printZeroNever().toFormatter(); | |
} | |
return formatter.print(period); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this.