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
4
votes
2 answers

java.time.LocalDate vs Instant for a 'business date'

I want to represent a 'business date', eg a transaction that happened 'on 3 June 2019'. We actively ignore timezones for this purpose, in full knowledge that 'on 3 June 2019' in Japan might be 'on 2 June 2019' in the US - and ordering within the…
Oli
  • 582
  • 1
  • 6
  • 18
4
votes
2 answers

ScalaTest: treat Instants as equal when in the same millisecond

I have a case class that I serialize to JSON, and a test case that checks that round-tripping works. Buried deep inside the case class are java.time.Instants, which I put into JSON as their epoch milliseconds. Turns out that an Instant actually has…
Thilo
  • 257,207
  • 101
  • 511
  • 656
4
votes
0 answers

How convert bytea in timestamp?

I have an entity with a property of type java.time.Instant. @ApiModelProperty(required = false) private Instant date; I am using PostgreSQL and this column was converted to bytea. The hibernate show in the console a query like this: select…
Luciano Borges
  • 817
  • 3
  • 12
  • 31
3
votes
4 answers

Why does LocalDateTime.ofInstant() requires ZoneId

In Java, If Instant represents a point in time, encoded as date and time in UTC. And LocalDateTime represents a point in time, encoded as date and time in the JVM local timezone. Why then does LocalDateTime.ofInstant() require a ZoneId as a second…
Mike
  • 53
  • 1
  • 5
3
votes
2 answers

Parse string with offset to Instant Java 11

I am trying to parse the following string 2021-10-15T08:39:05+02:00 into an Instant this works seamlessly using Java 15 but throws an error for Java 11. java.time.format.DateTimeParseException: Text '2021-10-19T11:06:35+02:00' could not be parsed at…
joachim
  • 652
  • 2
  • 7
  • 23
3
votes
1 answer

Error while parsing 2018-05-01T00:00:00 date using Instant.parse

Here is my code which i am using to parse string using Instant.parse , String date = "2018-05-01T00:00:00"; Instant.parse(date) And getting below error java.time.format.DateTimeParseException: Text '2018-05-01T00:00:00' could not be parsed at…
Wit Wikky
  • 1,542
  • 1
  • 14
  • 28
3
votes
4 answers

The difference between 2 Instants in Calendar Days

So I'm trying to get a specific number with my code. Right now I have: Instant Today = 2018-07-17T13:45:00Z Instant Expiration1 = 2018-07-18T11:00:00Z long daysTilExp = Today.until(Expiration, Chronounit.DAYS) The problem is that because this isn't…
TOTOROCATBUS
  • 172
  • 1
  • 2
  • 17
3
votes
1 answer

How can I initialize Instant in Java

How can I initialize an instant type? I tried this: Instant instant = new Instant(); But doesn't work.. I need it because after on Freemarker I have to do this: [#assign dateFormated = newDate.from(instant.ofEpochSecond(data.time.seconds))/]
Tonino Fernandez
  • 441
  • 4
  • 12
3
votes
1 answer

Cannot deserialize java.time.Instant

I have a RestEasyClient that has to deserialize an object that has a java.time.Instant inside. I tried to register the new JavaTimeModule from jsr310 but still got errors: ObjectMapper mapper = new ObjectMapper() .registerModule(new…
Mircea Stanciu
  • 3,675
  • 3
  • 34
  • 37
3
votes
0 answers

Java's System.Time.Instant.now is only updating in 15 millisecond intervals

I am using System.Time.Instant to determine how quickly a web address can respond to a simple request. My overall goal is to determine latency between my home computer and a service that I set up on a remote machine that is 200 miles away. Here's a…
3
votes
1 answer

Joda-Time to java.time migration 'fromDateFields()'

We are currently migrating from Joda-Time to java.time. I have the following doubts about the fromDateFields()method. Old joda code: Date date = new Date(); //some java Date LocalDateTime lt = LocalDateTime.fromDateFields(date); A colleague…
Lonzak
  • 9,334
  • 5
  • 57
  • 88
3
votes
0 answers

Formatting java.time.Instant bean property in springboot 1.5.3 and jaxrs

I'm using Jaxrs, to create Rest services with springboot 1.5.x. I have a bean with an Instant property. When I call my service instead of getting { "startTime": { "epochSecond": 1517243670, "nano": 986000000 } } I would like…
2
votes
1 answer

java.time.Instant does not render on the consumer side

I am trying to send some information with Kafka. I have a class to handle this task. The class includes a private variable called "timestamp" of type Instant. When the timestamp is generated, it renders correctly. However, when I receive the message…
2
votes
2 answers

Parsing Instant using OpenCsv

I am trying to parse Instant from a CSV using OpenCsv this way: @CsvDate("yyyy-MM-dd hh:mm:ss") @CsvBindByName(column = "date") private Instant date; I know that OpenCsv is supposed to support java.time. But when trying to use it I am getting the…
Tom Carmi
  • 385
  • 1
  • 5
  • 18
2
votes
1 answer

Hibernate not parsing values around DST transitions correctly

I've got a problem where an Instant that occurs during the DST transition is being persisted correctly to the database, but when read back is returning a different value. Specifically, I am in Europe/London and am having a problem with…
Jakg
  • 922
  • 12
  • 39
1 2
3
8 9