Java — How to get current epoch timestamp | Code Factory

Get current timestamp in Java using System.currentTimeMillis()

package com.example.java.programming.datetime;/**
* @author code.factory
*
*/
public class Test {
public static void main(String... args) {
// Get epoch timestamp using System.currentTimeMillis()
long currentTimestamp = System.currentTimeMillis();
System.out.println("Current epoch timestamp in millis: " + currentTimestamp);
}
}
Current epoch timestamp in millis: 1593423347845

Get current timestamp in Java using the Instant class

package com.example.java.programming.datetime;import java.time.Instant;/**
* @author code.factory
*
*/
public class Test {
public static void main(String... args) {
// Get current timestamp using Instant
long currentTimestamp = Instant.now().toEpochMilli();
System.out.println("Current epoch timestamp in millis: " + currentTimestamp);
}
}
Current epoch timestamp in millis: 1593423516547

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Every coder should switch to this new IDE

5 reasons why Ethernet Connectivity Fault Management saves time and money

Deploy a Docker Registry Using Self-Signed Certificates and htpasswd

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

Using BPMN Visualization in R

What is S token in SakeSwap protocol, and why it is very important to trade mining?

A brief explanation of Static Libraries

Conditional Statements in Java

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Exception handling In Java.

Multithreading Concept in JAVA

Trending things to know in Java

Artificial Intelligence and many more things to know in 2022 by use of JAVA

Time Conversion | HackerRank Problem | Java Solution