I need to display tomorrow's date only , l have this code and his working fine without problem . and he is give the current date for today. l want change this code to get the date for tomorrow but l dont know how !
private fun date24hours(s: String): String? {
try {
val sdf = SimpleDateFormat("EE, MMM d, yyy")
val netDate = Date(s.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
I might be late to the party, but this is what I found works for me
const val DATE_PATTERN = "MM/dd/yyyy"
internal fun getDateTomorrow(): String {
val tomorrow = LocalDate.now().plusDays(1)
return tomorrow.toString(DATE_PATTERN)
}
It is possible to use Date for this, but Java 8 LocalDate is a lot easier to work with:
// Set up our formatter with a custom pattern
val formatter = DateTimeFormatter.ofPattern("EE, MMM d, yyy")
// Parse our string with our custom formatter
var parsedDate = LocalDate.parse(s, formatter)
// Simply plus 1 day to make it tomorrows date
parsedDate = parsedDate.plusDays(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With