Skip to content

Instantly share code, notes, and snippets.

@dnorton
Last active March 18, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnorton/2323d3c14fe91798d56e to your computer and use it in GitHub Desktop.
Save dnorton/2323d3c14fe91798d56e to your computer and use it in GitHub Desktop.
when will then be now?
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