Convert Date to Timestamp in Scala
date, java, scala, timestamp
Solution
Why not something as simple as using `Date.getTime()`?
new java.sql.Timestamp(date.getTime)
You don't need Joda time for this. Scala isn't really relevant here, unless you need an implicit conversion:
//import once, use everywhere
implicit def date2timestamp(date: java.util.Date) =
new java.sql.Timestamp(date.getTime)
val date = new java.util.Date
//conversion happens implicitly
val timestamp: java.sql.Timestamp = date
Problem
In Scala, I am converting Date to Timestamp. I am currently doing this with: ``` val date = new java.util.Date() new java.sql.Timestamp(new org.joda.time.DateTime(date).getMillis) ``` Is there a slicker way of doing this? Java-informed responses would also be relevant.