Kotlin .atDate()
Published Dec 27, 2023
Contribute to Docs
The .atDate() method in Kotlin is a function that combines date and time into a LocalDateTime object. This method is beneficial when creating a complete timestamp by merging separate LocalDate and LocalTime instances.
Syntax
localTime.atDate(localDate)
localTime: The time component.localDate: The date component.
Example
This example demonstrates combining a time and a date:
import java.time.LocalDateimport java.time.LocalTimeimport java.time.LocalDateTimefun main() {val date = LocalDate.of(2023, 12, 25)val time = LocalTime.of(15, 30)val dateTime = time.atDate(date)println(dateTime)}
The above example will give the following output:
2023-12-25T15:30
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours