Skip to content

Instantly share code, notes, and snippets.

@Tamkien
Created October 20, 2020 06:45
Show Gist options
  • Save Tamkien/51ddc3309b69ca637590d38a8227f989 to your computer and use it in GitHub Desktop.
Save Tamkien/51ddc3309b69ca637590d38a8227f989 to your computer and use it in GitHub Desktop.
A function to add a field (Calendar.SOMETHING) into a given date. To minus, put a negative number.
private fun Date.add(field: Int, amount: Int): Date = Calendar.getInstance().let { calendar ->
calendar.time = this@add
calendar.add(field, amount)
return@let calendar.time
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment