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
  • 335
  • 1
  • 4
  • 23
vijay
  • 9
  • 2
  • 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())`. – Felipe 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

7

Use java.time instances when you work with time

java.time.Instant.now.toEpochMilli
Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64