Questions tagged [java.time.instant]

The Java class to represent an instantaneous point on the time-line. This might be used to record event time-stamps in the application. Use this tag for questions about the java.time.Instant class or its ThreeTen Backport equoivalent, org.threeten.bp.Instant. If your question involves more classes from the java.time API, rather consider the java-time tag and/or the jsr310 tag.

The Instant class is part of the modern Java date and time API known as java.time or JSR-310. It replaces the old classes java.util.Date and java.sql.Timestamp.

As part of the modern API Instant is built-in with Java 8 and later, and is available in Java 6 and 7 through the ThreeTen Backport, the backport of JSR-310 to Java 6 and 7.

The Instant class is immutable and therefore threadsafe.

Motivation: this tag was created in part because the instant tag was often incorrectly used for questions about java.time.Instant.

Resources:

  1. The official documentation of java.time.Instant (javadoc)
  2. ThreeTen Backport - provides a backport of the Java SE 8 date-time classes to Java SE 6 and 7.
133 questions
0
votes
0 answers

Reset a java variable Instant type to zero or clear it

I'm implementing some services in JAVA to a call center. I need to record the duration of a call so I'm using this to do that: last = Instant.now(); Duration duration = Duration.between(first, last); tfinal=Timestamp.from(last); Long minutos; Long…
Liz Castillo
  • 59
  • 1
  • 9
0
votes
1 answer

java 8 instant with time 00:00:00 gives time 02:00:00 after conversion to util,Date

I have a problem in converting java.time.Instant to java.util.Date: System.out.println(item.getStart()); // getStart returns instant System.out.println(Date.from(item.getStart())); gives output: 2017-08-29T00:00:00Z Tue Aug 29 02:00:00 CEST…
0
votes
1 answer

Java CommonsLang StringUtils.isBlank on instant

I know it's a silly question but here's my issue. I'm working on an object and needed to check all the member variables for nullity, empty chars etc... but in my object I don't only have strings, I also have Instant and Booleans. I've tried with…
raik
  • 33
  • 2
  • 13
-1
votes
1 answer

How do I convert a Java Date into an Instant for a given timezone?

I have an instance of the Date class and a time zone (e.g Europe/London). How do I convert this into an Instant? Is the below the correct way of doing this? LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(),…
-1
votes
2 answers

Are there any annotations for resolving java.time.Instant deserialization errors. I am getting this error as I have a dateType field as Instant

Error: Java 8 date/time type** java.time.Instant** not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310 I have followed forum comments and added relevant dependencies and mapper, but couldn't resolve…
-1
votes
1 answer

How to remove decimal point in an Java Instant data type

I get this error whenever I try to remove the decimal point of the Instant datatype in java. ! java.util.IllegalFormatConversionException: M != java.time.Instant Here is the line of code I am trying to use for the conversion. I am using…
-1
votes
2 answers

java.time.Instant could not be parsed from string like '2016-07-02T00:00:00Z'

In REST API Response I am getting date as '2016-07-02T00:00:00Z' In code, I have a column like below @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "UTC") private Instant effectiveDate; // getter & setter public Instant…
Arjun
  • 45
  • 2
  • 11
-1
votes
3 answers

Get the current hour and minutes from Instant.now()

Consider the below code Instant instant = Instant.now(); System.out.println(instant); RESULT: 2020-01-13T09:01:06.405Z Now from the above result I want get the current hour and current minutes.
Ren
  • 41
  • 1
  • 1
  • 2
-1
votes
1 answer

Rewrite UNIX time with nanosecond precision

I have a unix time since epoc in milisecond e.g.: 1505913038295 I need to slice this into two things. So I can use with the Java Instant class method. Instant ofEpochSecond(long epochSecond, long nanoAdjustment) Seconds since epoch (This I can…
mrmannione
  • 749
  • 10
  • 29
-2
votes
1 answer

Force the local datetime to a given value, in order to perform a JUnit test

In my Java application I have to write an Unit Test and I have to check that this test works in both time of the year Daylight savings time / Normal time. To do that, I should set an hardcoded datetime that override the server datetime; execute my…
Archimede
  • 699
  • 3
  • 15
  • 28
-2
votes
1 answer

C# equivalent to Java's Instant class and RsaSHA256Signer class

I am trying to convert some java source code to C#. What is the equivalent of the following Java classes in c#: RsaSHA256Signer Instant Thank you
koko
  • 1
  • 2
-3
votes
3 answers

Java Instant.parse cannot validate date

I have an instant field and trying to validate the values in this field using the following approach: Instant.parse("2021-09-29 09:35:07.531") However, it throws the error: java.time.format.DateTimeParseException: Text '2021-09-29 09:35:07.531'…
Jack
  • 1
  • 21
  • 118
  • 236
-4
votes
2 answers

Create first Instant of year 2022

I have an int representing the year 2022, and I want to create an Instant object representing the first instant of the year, meaning: 2022-01-01 00:00:00. int year = 2022; Instant instant = ... How can we do that in java 8?
1 2 3
8
9