Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get the current timestamp in Java8

Shulou Source: shulou.com Published: 2022-06-01 02:14:03 09月21日 Update

This article mainly introduces how to get the current timestamp in Java8, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

Get the current timestamp in Java 8

The Instant class has a static factory method now () that returns the current timestamp, as shown below:

Package com.shxt.demo02; import java.time.Instant; public class Demo16 {public static void main (String [] args) {Instant timestamp = Instant.now (); System.out.println ("What is value of this instant" + timestamp.toEpochMilli ());}}

Both date and time are included in the timestamp information, much like java.util.Date. In fact, the Instant class is indeed equivalent to the Date class before Java 8, you can use the respective conversion methods of the Date class and the Instant class to convert each other, for example: Date.from (Instant) to convert Instant to java.util.Date,Date.toInstant () is to convert the Date class to the Instant class.

Thank you for reading this article carefully. I hope the article "how to get the current timestamp in Java8" shared by the editor will be helpful to you. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Time article at the same time method value information interest reality actually factory date more friends knowledge editing industry information information channel static channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Microsoft Apple Huawei