“KOTLIN DATA TO STRING” Kod odpowiedzi

KOTLIN DATA TO STRING

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

fun main(args: Array<String>) {
    val current = LocalDateTime.now()
    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
    val formatted = current.format(formatter)
    println("Current Date and Time is: $formatted")
}
// Current Date and Time is: 2021-04-10 10:28:21.052
VasteMonde

Data do ciągnięcia Kotlin

//create an extension function on a date class which returns a string
    private fun Date.dateToString(format: String): String {
    //simple date formatter
        val dateFormatter = SimpleDateFormat(format, Locale.getDefault())
        
        //return the formatted date string
        return dateFormatter.format(this)
    }
    
    
    //call the extension function on a date object
    val timestampt = Date()
    val dateString = timestamp.dateToString("hh:mm a E dd-MMM")
Coder Thirteen

Odpowiedzi podobne do “KOTLIN DATA TO STRING”

Pytania podobne do “KOTLIN DATA TO STRING”

Więcej pokrewnych odpowiedzi na “KOTLIN DATA TO STRING” w Kotlin

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu