Java – converts dates to timestamps in scala
•
Java
In Scala, I convert date to timestamp I am doing this:
val date = new java.util.Date() new java.sql.Timestamp(new org.joda.time.DateTime(date).getMillis)
Is there a way to do this? The response to the Java notification will also be relevant
Solution
Why not use date Gettime ()?
new java.sql.Timestamp(date.getTime)
You don't need joda's time Scala is not important here unless you need 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
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码