How to extract date and time from Long type variable in Kotlin

var time="1587483014960"

I have a varible which gives the time in milliseconds, now i want to extract date and time from that variable. How can I do this in Kotlin?


  • April 21, 2020

    With below code you can get time and date from given milliseconds variable 


    import java.text.SimpleDateFormat 
    import java.util.Date 

    fun formatDateTime (time: Long): String { 
        val date = Date(time) 
        val format = SimpleDateFormat("dd/M/yyyy hh:mm:ss") 
        return format.format(date)



Have More Question?

Subscribe For Daily Updates

Flutter Questions
Android Questions