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,
- How to get Java Thread name Example [Program]
- Java 8: Get First and Last Date of the Week for Given Date
- Convert String to int in Java
- How to Get List of All Country Codes in Java Using Locale Class
- Convert Multidimensional Array toString In Java
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Create a Zip file using Java Code programmatically
- [Fix] java.net.MalformedURLException: unknown protocol
- [fix] Java JDBC ConnectException: Connection refused
- Read Json File and Convert to Java Object using Jackson
- list of jars required for hibernate 4.x.x
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java: The value of the local variable string is not used
- [fix] URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs) IntelliJ
- Java 8+ get Day of the Week Examples with LocalDateTime, DateTime, ZonalDateTime and Instant classes
- Run SQL Script file using Java JDBC Code Example
- Remove Trailing zeros BigDecimal Java
- Java JDBC IN Clause Example with PreparedStatement MySQL
- Convert Java List to Json String using Jackson
- Java 8 foreach loop code examples
- error: file not found: HelloWorld.java
- IntelliJ Keyboard Shortcut to remove unused imports [Java]
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Struts 2 Hello World Example in Eclipse
More Posts:
- SQL: Check if table exists - HowTos
- [fix] Docker - no matching manifest for linux/arm64/v8 in the manifest list entries [M/M2 Mac] - Docker
- How to identify the version of IntelliJ - HowTos
- How to remove or unstage a file from git staged area - Git
- How to Schedule Mails in macOS Ventura - MacOS
- How to check file permissions for your file using Linux/Unix/macOS Terminal Command - Linux
- Display full website URL/address in Safari macOS Browser - MacOS
- How to install homebrew (brew) on M1 Mac - MacOS