🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this guide, you will learn about the Instant ofEpochMilli() method in Java programming and how to use it with an example.
1. Instant ofEpochMilli() Method Overview
Definition:
The ofEpochMilli() method of the Instant class in Java is used to obtain an instance of Instant using milliseconds from the epoch of 1970-01-01T00:00:00Z.
Syntax:
public static Instant ofEpochMilli(long epochMilli)
Parameters:
- epochMilli: The number of milliseconds from 1970-01-01T00:00:00Z.
Key Points:
- The ofEpochMilli() method is a static method and can be invoked on the Instant class itself.
- It takes as a parameter the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.
- This method can be used to convert a timestamp in milliseconds to an Instant object.
2. Instant ofEpochMilli() Method Example
import java.time.Instant;
public class InstantOfEpochMilliExample {
public static void main(String[] args) {
// Creating an Instant from milliseconds from the epoch
long millisecondsFromEpoch = 1632131130123L; // Example timestamp in milliseconds
Instant instant = Instant.ofEpochMilli(millisecondsFromEpoch);
// Displaying the created Instant
System.out.println("Instant from Epoch Milli: " + instant);
}
}
Output:
Instant from Epoch Milli: 2021-09-20T09:45:30.123Z
Explanation:
In this example, we have used the ofEpochMilli() method to create an Instant from a given timestamp in milliseconds (1632131130123L). The output displays the created Instant in the ISO-8601 format corresponding to the specified timestamp.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment