Last active
March 18, 2016 15:07
-
-
Save dnorton/2323d3c14fe91798d56e to your computer and use it in GitHub Desktop.
when will then be now?
This file contains hidden or 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
import java.time.Duration | |
import java.time.LocalDateTime | |
import java.time.format.DateTimeFormatter | |
/** | |
* Dates | |
*/ | |
fun futureDate(days : Int) : String { | |
val currentDateTime : LocalDateTime = LocalDateTime.now() | |
val futureDateTime : LocalDateTime = currentDateTime.plus(Duration.ofDays(days.toLong())) | |
return futureDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE) | |
} | |
fun pastDate(days : Int) : String { | |
val currentDateTime : LocalDateTime = LocalDateTime.now() | |
val futureDateTime : LocalDateTime = currentDateTime.minus(Duration.ofDays(days.toLong())) | |
return futureDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE) | |
} | |
fun main(args: Array<String>) { | |
val days: Int = 60 | |
println ("today is ${LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE)}") | |
println("$days days in the future is ${futureDate(days)}") | |
println("$days days in the past was ${pastDate(days)}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment