By Alvin Alexander. Last updated: April 11, 2018
If you ever need to convert a Java Date
to a Long
, just call the getTime
method on the Date
instance. This Scala example shows the process:
scala> import java.util.Calendar import java.util.Calendar scala> val d = Calendar.getInstance.getTime d: java.util.Date = Tue Jan 16 19:34:37 MST 2018 scala> d.getTime res0: Long = 1516156477659
Even though that code is written in Scala, as you can see, it’s easy to convert that code to Java. If you ever need to convert a Java Date
to a Long
value (technically a long
in Java), I hope this example is helpful.