You can get the Timestamp in Java in various ways, let's see some examples,
Example 1: Using Date class (java.util.Date)
Date date = new Date(System.currentTimeMillis());
System.out.println(date);
Output: Sat Jul 24 10:55:39 PST 2021
Example 2: Using Date class (java.sql.Date)
The default Date constructor from java.sql package only prints out the date in yyyy-MM-dd format,
Date date = new Date(System.currentTimeMillis());
System.out.println(date);
Output:2021-07-25
Example 3: Using Timestamp class
Timestamp class from java.sql package extends the java.util.Date class,
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
System.out.println(timestamp);
Output: 2021-07-25 13:51:48.021

Java Get Timestamp example
Read more: https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Timestamp.html
Have Questions? Post them here!
More Posts related to Java,
- [Fix] java.time.zone.ZoneRulesException: Unknown time-zone ID
- Parse XML file in Java using DOM Parser
- Java equals method - Tutorial
- [Program] How to read three different values using Scanner in Java
- Java: The value of the local variable string is not used
- Display Output in Java Console as a Table
- How to detect Operating System using Java code
- Java 8 Streams map() with examples
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Add newline character Java code example (\r \n \r\n)
- List of Java Major Minor Version Numbers
- IntelliJ Keyboard Shortcut to remove unused imports [Java]
- Java - Check if array contains the value
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- XmlRpcException ConnectException connection refused error
- Create a Zip file using Java Code programmatically
- List of jar files for Jax-ws (SOAP) based Java Web Services
- How to fix Java HTTP java.net.UnknownHostException
- List of jars required for Struts2 project
- [fix] java: incompatible types: double cannot be converted to java.lang.Integer Generics
- Maven BUILD FAILURE: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
- Get the current timestamp in Java
- java: unclosed string literal [Error]
More Posts:
- Android Activity Main xml stuck loading - Android-Studio
- How to create StackOverflow error in java - Java
- How to fix: You will need Google Chrome to install most apps, extensions and themes. - Chrome
- Sublime Text 3 Convert Case to Upper, Lower, Title or Swap - Sublime-Text
- Java -Day of the week using Java 8 DayOfWeek Enum - Java
- SharePoint list excel import error - Title is a required filed and can't be empty - SharePoint
- How to send SMS on Android Emulator - Android
- Users experience call quality issue, voice distortion, disconnection with Microsoft Teams call and meeting - Teams