How to convert date string to timestamp in Kotlin?

elegant-user picture elegant-user · Feb 17, 2018 · Viewed 39.4k times · Source

I want to convert a date string to unix timestamp from a date string e.g. 14-02-2018

Can someone help?

Answer

Arpan Sarkar picture Arpan Sarkar · Feb 17, 2018

use this to convert the date string to UNIX timestamp

val date = SimpleDateFormat("dd-MM-yyyy").parse("14-02-2018")
println(date.time)