If you have an Instant class object and you want to convert it to a Local date and time then you can make use of the ofInstant() method from the LocalDateTime class,
Example:package org.code2care;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* Code2care Java Examples
*
* Convert Instant to LocalDateTime
*
*/
public class JavaInstantClassExample {
public static void main(String[] args) {
Instant timeStampUTC = Instant.now();
LocalDateTime timeInAmericaChicago = LocalDateTime.ofInstant(timeStampUTC, ZoneId.of("America/Chicago"));
System.out.println("GMT/UTC Instant TimeStamp:" + timeStampUTC);
System.out.println("America/Chicago TimeStamp:" + timeInAmericaChicago);
}
}
Output:
GMT/UTC Instant TimeStamp:2022-05-13T19:30:17.005796Z
America/Chicago TimeStamp:2022-05-13T14:30:17.005796

More Posts related to Java,
- Drop table using Java JDBC Template
- Java - Check if array contains the value
- YAML Parser using Java Jackson Library Example
- Java Jackson ObjectMapper Class with Examples
- Get Client IP address from HTTP Response in Java
- How to Word-Warp Console logs in IntelliJ
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Setting Java_Home Environment variable on Windows Operating System
- Fix: Maven - Failed to execute goal - Compilation failure - Source/Target option 5 is no longer supported. Use 7 or later
- Java SE JDBC Select Statement Example
- How to extract Java Jar/War/Ear files in Linux
- java: unclosed string literal [Error]
- [Solution] Exception in thread main java.util.EmptyStackException
- Read YAML file Java Jackson Library
- What Java version is used for Minecraft 1.18
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Program] How to read three different values using Scanner in Java
- Java 8 Predicate Functional Interface Examples
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Convert String Date to Date Object in Java
- Struts 2 Hello World Example in Eclipse
- Read a file using Java 8 Stream
- Java - How to set custom thread name?
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- java: ']' expected error [fixed]
More Posts:
- What version of windows do I have? - Microsoft
- Check Reboot History Mac - MacOS
- How to force quit or kill Notepad++ Process - NotepadPlusPlus
- How to Use Command Prompt on a Mac? - MacOS
- How to send WhatsApp message from your Android App using Intent - WhatsApp
- Make div element draggable using jQuery - jQuery
- Be right back We’re making updates to the Apple Store. Check back soon. - Apple
- Android Studio Error: Default Activity not found - Android-Studio