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,
- Java equals method - Tutorial
- Unbound classpath container: JRE System Library [JavaSE-1.7]
- Spring Boot: @RequestBody not applicable to method
- Java 8: Steam map with Code Examples
- Java Program: Random Number Generator
- Java java.time.Clock class code examples [Java Date Time API]
- Fix: type argument is not within bounds of type-variable T
- [Fix] java.net.MalformedURLException: unknown protocol
- Java 7 addSuppression() and getSuppression() Exception Handling
- Convert Java Array to ArrayList Code Example
- How to Word-Warp Console logs in IntelliJ
- Ways Compare Dates in Java Programming with Examples
- Remove Trailing zeros BigDecimal Java
- CRUD operations in Spring Boot + JDBC
- [Java Threads] Should we extend Thread Class or implement Runnable interface
- Json Serialization and Deserialization using Java Jackson
- Create simple struts2 project using maven commands
- How to install Java OpenJDK 11 on Alpine Linux
- Unsupported major.minor version 52.0 in java
- Error: Can not find the tag library descriptor for
- Java: Convert String to Binary
- How to run Java Unit Test cases with Apache Maven?
- Java: Testing Private Methods in JUnit using reflection API Example
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java Join Strings with Comma Separator
More Posts:
- apt-get list --installed packages in Ubuntu Linux - Ubuntu
- How to get unique values from a list in Python - Python
- SQL: Check if table exists - HowTos
- What is $$ in Bash Shell Script- Special Variable - Bash
- Open New tab using keyboard shortcut in Mac Terminal - Mac-OS-X
- W3 HTML validator warning Unable to Determine Parse Mode - Html
- Show Hidden Files in Mac Terminal - MacOS
- Disable Fading Edges Scroll Effect Android Views - Android