How to Get Current Timestamp in Java


In this example we will show the method to get current timestamp in java.

Source Code

package com.beginner.examples;

import java.sql.Timestamp;

public class CurrentTimestamp {
    public static void main(String[] args) {
       Timestamp time = new Timestamp(System.currentTimeMillis()); // get current timestamp
       System.out.println(time);
    }
}

Output:

2020-06-15 09:12:50.892

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments