Horje
kotlin date to string Code Example
kotlin date 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
date to string 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")




2

Related
how to declare string array in kotlin Code Example how to declare string array in kotlin Code Example
date format kotlin Code Example date format kotlin Code Example
android custom AlertDialog theme Code Example android custom AlertDialog theme Code Example
string array in kotlin Code Example string array in kotlin Code Example
2d array in kotlin Code Example 2d array in kotlin Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11