34

I know, how to convert a Timestamp to a long, with the getTime() method.

Is there a method that convert a long to a TimeStamp?

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
Adam Sh
  • 8,137
  • 22
  • 60
  • 75

5 Answers5

62

The constructor is doing that:

Timestamp(long time) 
evanwong
  • 5,054
  • 3
  • 31
  • 44
29

See: Timestamp.Timestamp(long):

new Timestamp(someLong)
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
1

Yes, there's a constructor for Timestamp that takes a long as a parameter. http://docs.oracle.com/javase/6/docs/api/java/sql/Timestamp.html#Timestamp(long)

dj_segfault
  • 11,957
  • 4
  • 29
  • 37
0

Java 8 Timestamp DOES include a constructor with long. documentation

RockyRoads
  • 11
  • 2
-1

This question is a bit old but for those arriving here scratching their heads because their Timestamp object does not include a (long) constructor, Firebase's com.google.firebase.Timestamp object include (Date date) constructor. and (long seconds, int nanoseconds) and Date does include a (long) constructor (which creates a date object based of number of seconds from epoch - same as java.sql.Timestamp

bottom line is your solution is simply either

Timestamp(new Date(longEpochTimeVar));

or

Timestamp(longEpochTimeVar,0);

0 stands for 0 nanoseconds so both option will produce the same result.

Joe
  • 2,252
  • 1
  • 22
  • 32