
Unsupported unit Years
If you have created an object of Instant class from the Java Date and Time API and you are trying to add or subtract Years from it you will get this error!
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException:
Unsupported unit: Years
at java.base/java.time.Instant.plus(Instant.java:861)
at org.code2care.JavaInstantClassExample.main(JavaInstantClassExample.java:13)
Reason:
Instant class deals with time in seconds/milliseconds and epoch time and does not deal with a date.
Solution:You will need to convert the instant to a LocalDateTime and then add units like years.
More Posts related to Java,
- How to install Java 11 on Mac
- Get Client IP address from HTTP Response in Java
- SharePoint Open in the client application document opens in browser
- How to verify if java is installed on the computer and get version detail
- Java - Check if array contains the value
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- How to run Java Unit Test cases with Apache Maven?
- What Java version is used for Minecraft 1.18
- List of jar files for Jax-ws (SOAP) based Java Web Services
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- Convert Instant timestamp into LocalDateTime Java Code Example
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Create simple struts2 project using maven commands
- Java - PatternSyntaxException
- List of Online Java compiler with console
- Minecraft Java Edition
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- Java XML-RPC 3.1.x based web service example
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java 8 foreach loop code examples
- Java -Day of the week using Java 8 DayOfWeek Enum
- Java 8 - Convert List to Map Examples
- Java: TimeZone List with GMT/UTC Offset
- list of jars required for hibernate 4.x.x
More Posts:
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier. - Git
- Get Wifi Details : Android Programming - Android
- Notepad++ display files on tab bar as horizontal instead of vertical - NotepadPlusPlus
- How to know list of images available on your device - Docker
- SharePoint installation - Appfabric installation failed because installer MSI returned with error code:1603 - SharePoint
- Android Studio 4.2 Canary 1 now available - Android-Studio
- How to Detect Phone Shakes Android Programming - Android
- Pass data between two Android Activities and access it using Intent - Android