我只需要显示明天的日期,我有这段代码并且他的工作正常没有问题。他给出了今天的当前日期。我想更改此代码以获得明天的日期,但我不知道如何!
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()
最佳答案
可以为此使用 Date
,但 Java 8 LocalDate
更容易使用:
// 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)
关于date - Kotlin 只获取明天的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53371132/