gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)
kotlin get current data string
- User
kotlin get current data string
- Assistant
In Kotlin, you can get the current date as a string using the
LocalDateclass from thejava.timepackage. Here is an example:import java.time.LocalDate import java.time.format.DateTimeFormatter fun main() { val currentDate = LocalDate.now() val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") // Define the format you want val currentDateString = currentDate.format(formatter) println(currentDateString) }In the example above, we obtain the current date using
LocalDate.now(). Then, we define the desired date format usingDateTimeFormatter. Finally, we format the current date as a string using the formatter'sformat()method.This will print the current date in the specified format, such as "2022-01-01". You can modify the
DateTimeFormatterpattern to match your desired format.