In Kotlin, you can use the Date and SimpleDateFormat classes to convert between the Long (a representation of time in milliseconds since epoch) and Date (date and time objects) data types.
Here is an example of converting from Long to Date and vice versa:
fun convertLongToTime (time: Long): String { val date = Date(time) val format = SimpleDateFormat( "yyyy.MM.dd HH:mm" ) return format.format(date) } fun currentTimeToLong (): Long { return System.currentTimeMillis() } fun convertDateToLong (date: String): Long { val df = SimpleDateFormat( "yyyy.MM.dd HH:mm" ) return df.parse(date).time }
Note that the SimpleDateFormat class is not used in this example because we only need to convert between Long and Date . If you need to display the date in a specific format, you can use SimpleDateFormat to format the date display to your needs.