java tutorial - How to get current timestamp using Java - java programming - learn java - java basics - java for beginners
Learn java - java tutorial - current time stamp in java - java examples - java programs
Current timestamp in Java:
- It is quite easy to get the current timestamp in java. By using
Date
andTimestamp
class.
- Here are the steps that we have followed in the below example:
- Created the object of Date class.
- Got the current time in milliseconds by calling
getTime()
method of Date. - Now created object of
Timtestamp
class and then passed the given milliseconds which we get in step two, to the constructor of this class through the creation of object. It will build timestamp using the already provided milliseconds value.
Syntax
- A thin wrapper around “java.util.Date” that allows the JDBC API to identify this as an SQL TIMESTAMP value. It includes the capacity to hold SQL TIMESTAMP for fractional seconds value, which permits this requirement of fractional seconds into precision of nanoseconds.
- A Timestamp can also offer formatting and then parsing operations to keep up the JDBC (Java Database Connectivity) escape syntax for timestamp values.