“Comment obtenir la date actuelle à Kotlin” Réponses codées

Obtenez l'heure actuelle à Kotlin

// declaration
var c : Calendar = Calendar.getInstance()
private var df : SimpleDateFormat? = null
private var formattedDate = ""

// goes to main method or onCreate(Android) 
df = SimpleDateFormat("dd-MM-yyyy HH:mm a")
formattedDate = df!!.format(c.time)
println("Format dateTime => $formattedDate")
Dizzy Dunlin

Comment obtenir la date actuelle à Kotlin

import java.time.LocalDateTime
import java.time.temporal.ChronoField;  

fun main() {
    
    val current = LocalDateTime.now()
    println(current) // 2021-12-24T13:15:28.602
    
    println("Today is: \n ${current.get(ChronoField.DAY_OF_MONTH)} \n Month: ${current.get(ChronoField.MONTH_OF_YEAR)} \n Year: ${current.get(ChronoField.YEAR)}")
    
  /*
   Today is: 24 
   Month: 12 
   Year: 2021
   
    */
    
}
an-jorge

Réponses similaires à “Comment obtenir la date actuelle à Kotlin”

Questions similaires à “Comment obtenir la date actuelle à Kotlin”

Plus de réponses similaires à “Comment obtenir la date actuelle à Kotlin” dans Kotlin

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code