Java API Tutorial - Java Timestamp(long time) Constructor








Syntax

Timestamp(long time) constructor from Timestamp has the following syntax.

public Timestamp(long time)

Example

In the following code shows how to use Timestamp.Timestamp(long time) constructor.

public class Main {
  public static void main(String[] args) {
    java.util.Date today = new java.util.Date();
    java.sql.Timestamp ts1 = new java.sql.Timestamp(today.getTime());
//  w w  w  .  j a va  2 s.c  o m
    long tsTime1 = ts1.getTime();
    
    System.out.println(tsTime1);
  }
}

The code above generates the following result.