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

Find the day before today's date and after today's date

I have created a financial app and I want the app to show the financial month to the user. The financial months represents usually the day when the user gets the salary or the biggest income. That day could be the first of the month, the last day of…
Marian Pavel
  • 2,726
  • 8
  • 29
  • 65
0
votes
1 answer

Android error "org.threeten.bp.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds"

I am using the 'com.jakewharton.threetenabp:threetenabp:1.2.4' library for using Newer features DateTimeFormatter for lower apis version. I have a situation where I have to first convert the the date from the JSON response which is in…
0
votes
1 answer

Converting a separate date, hours, minutes, seconds, and AM/PM to a java.time.Instant

From the front end I am receiving a separate LocalDate (variable name is date), along with separate Integers for hours, minutes, seconds, and an "AM" or "PM" String, and I need to combine these into a java.time.Instant object to store in the…
0
votes
1 answer

ConcurrentSkipSet CompareTo Instant infinite loop

I am creating a java.util.concurrent.ConcurrentSkipListSet with a comparator. My comparator compares an Instant field in the object to determine the order. This is the comparator: public int compare(myObj first, myObj second) { if (first ==…
manic bubble
  • 147
  • 1
  • 3
  • 13
0
votes
1 answer

EpochSeconds from localdate in jdk8

I am getting error ofInstant not member of LocalDate in jdk 8. LocalDate.ofInstant(Instant.now(), zone).atStartOfDay(ZoneId.of("Z")).toEpochSecond It's running fine in jdk11. How can the same be done in most decent manner in jdk8.
ARYA
  • 223
  • 1
  • 5
  • 15
0
votes
1 answer

json to Instant with a field "yyyy-MM-ddThh:mm:ss" using GSON but get java.lang.NumberFormatException: For input string: "1999-08-24T00:00:00"

I am trying json parsing with gson in a small java applicaiton. I have a json string which comes from .Net business layer, has a field as "1999-08-24T00:00:00". In my model like User model, I have java.time.Instant birthDay field. With gson i am…
0
votes
3 answers

How to parse JSR-310 date to Instant?

I'm trying to parse lets say "2020-01-12+01:00" with JSR-310 time. I read it via DateTimeFormatter.ofPattern("yyyy-MM-ddVV"), however now if I want to transform that into a Instant via…
urSus
  • 12,492
  • 12
  • 69
  • 89
0
votes
1 answer

Is there any possible failed edge case, for the following fast way to remove nanoseconds and seconds components from timestamp?

Currently, we are using the following way to remove nanoseconds and seconds components from timestamp. public static long toMinuteResolution(long timestamp) { return…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
0
votes
0 answers

Why the Zone is required to convert from Instant to LocalDate

None of these classes have Zone information: java.util.Date (no Zone information) java.time.Instant (no Zone information) java.time.LocalDate (no Zone information) But according to this question: Convert java.util.Date to java.time.LocalDate the…
fidudidu
  • 399
  • 3
  • 10
0
votes
1 answer

JUnit Java Instant dependent tests

I'm using Instant.now() to get the current UTC millis, and then truncate it to the nearest hour. All my JUnit are failing because they are taking the current System time. How can I make Instant.now() return a fixed value which I could supply in the…
Novice User
  • 3,552
  • 6
  • 31
  • 56
0
votes
1 answer

Java 8 : Using Instant, How to retrieve ZoneId information

I'm using Java Instant for my use-case where I want to capture the exact moment in timeline for.eg, { When the user last visited my website }. This is when the data gets persisted in the backend (sql). It persists in UTC format as I use…
0
votes
3 answers

Can Instant.toEpochMilli() be used as a unique id?

I have to generate a unique Id which is readable as well hence cannot use UUID. So I thought of using Instant.toEpochMilli(). Can it be used as unique id?
humbleCoder
  • 667
  • 14
  • 27
0
votes
1 answer

Parsing date with differents possible format

I have to parse a String to a timestamp in UTC. The String can have those format : YYYY-MM-DDThh:mm:ss.sssZ YYYY-MM-DDThh:mm:ss.sss+/-hh:mm YYYY-MM-DDThh:mm:ss.sss (considered at UTC, so add a Z at the end) What's the best way to do this and…
BnJ
  • 1,024
  • 6
  • 18
  • 37
0
votes
1 answer

Localdatetime to epoch/calendar.getTimeInMillis() for alarmmanager

I'm getting the milliseconds for the alarmmanager to set repeating alarm and I'm getting strange results - I set alarm at 8:55 am LocalDateTime Earliest Day : 2018-05-22T08:55 Instant : 2018-05-22T08:55:00Z Then I used this method to get the…
Meep
  • 501
  • 6
  • 24
0
votes
2 answers

How to use DateTimeFormatter of java.time package in JDK 1.8?

How to use DateTimeFormatter of java.time package in JDK 1.8? When I use LocalDate I've got a Noclassdeffounderror. I changed my project from JDK 1.7 to 1.8. Is there any jar file to be added?
1 2 3
8
9