0

I am trying to generate a new epoch timestamp(eg 1435655706000) in scala. I've used the below function but got time format.

Val timestamp: Timestamp = new Timestamp(System.currentTimeMillis())
Santhosh
  • 295
  • 3
  • 22
vijay
  • 9
  • 1
  • 1
    it is better to use the `java.time.Instant.now.toEpochMilli` like the answer below. But in case you want to keep using Timestamp you have to use to full package `java.sql.Timestamp` when declaring this class -> `val timestamp: java.sql.Timestamp = new java.sql.Timestamp(System.currentTimeMillis())`. – Knoblauch Jan 18 '21 at 10:59
  • @Felipe, that is the second answer in the attached link :) You can upvote it – Tomer Shetah Jan 18 '21 at 11:04

1 Answers1

5

Use java.time instances when you work with time

java.time.Instant.now.toEpochMilli
Mateusz Kubuszok
  • 20,246
  • 4
  • 37
  • 56