Return a java.sql.Timestamp equal to the current time in Java

Description

The following code shows how to return a java.sql.Timestamp equal to the current time.

Example


//from w  w  w.  ja v a  2s  . c o m
public class Main {

  public static java.sql.Timestamp now() {
    return new java.sql.Timestamp(new java.util.Date().getTime());
  }

  public static void main(String[] argv) {
    System.out.println(now());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone