Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

kotlin get current data string

  1. User

    kotlin get current data string

  2. Assistant

    In Kotlin, you can get the current date as a string using the LocalDate class from the java.time package. 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 using DateTimeFormatter. Finally, we format the current date as a string using the formatter's format() method.

    This will print the current date in the specified format, such as "2022-01-01". You can modify the DateTimeFormatter pattern to match your desired format.