java.time.instant Questions

5

I think that java.time.Instant is the best choice to store a date into DB: it is the most likely TIMESTAMP and you are not depending by timezone, it is just a moment on the time. JPA supports Loc...
Aurignacian asked 15/3, 2018 at 20:58

3

Solved

I have an instance of Instant (org.joda.time.Instant) which I get in some api response. I have another instance from (java.time.Instant) which I get from some other call. Now, I want to compare the...
Gumption asked 22/7, 2016 at 17:36

5

Solved

I am trying to convert datetime in a string to an Instant instance using Java 8 or a utilities package. For example, String requestTime = "04:30 PM, Sat 5/12/2018"; to Instant reqInstant...
Holy asked 11/5, 2018 at 20:15

4

Solved

In Java, we can have many different ways to get the current timestamp, but which one is recommended: Instant.now().toEpochMilli() or System.currentTimeMillis()
Raft asked 5/11, 2019 at 6:31

10

Solved

I have an epoch second and a zoneId (see method1 below). It can be convert to LocalDateTime with system default zoneId, but I don't find the way to convert epoch second to LocalDateTime (see method...
Plotkin asked 17/9, 2015 at 9:21

1

A new interface java.time.InstantSource was added in Java 17. What is the use case of that additional abstraction if all implementations of that interface are Clock implementations too anyway?
Rew asked 15/9, 2021 at 20:59

5

Solved

In the application I am developing, I need to convert java.time.Instant object to java.sql.Timestamp. When I create Instant object like: Instant now = Instant.now(); I receive something like 2017-...
Singsong asked 13/3, 2017 at 14:54

2

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 ...
Indeterminacy asked 3/6, 2019 at 9:32

1

I just do not quite understand which one of those two I should use for the following example: We have an OfferEntity which has a member availableDay which is the date at which the offer is availab...

1

Solved

There has been changes in Java Date & Time API Since Java 9. LocalDateTime now has microseconds precision. Java 9 has a fresh implementation of java.time.Clock capable of capturing the curre...
Sebi asked 8/8, 2019 at 11:47

1

Solved

I have an instant formatted like this: DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT ) .withLocale( Locale.UK ) .withZone( ZoneId.of("UTC")); String in...
Stannic asked 21/4, 2019 at 4:54

5

Solved

The following piece of code: Instant inFourWeeks = Instant.now().plus(4L, ChronoUnit.WEEKS); Throws an exception: java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Weeks ...
Shopwindow asked 24/2, 2019 at 11:11

2

Solved

We have a library used for generating reports. It reads from a data file (SQL, XML, JSON, etc.), the datetime may then be modified in a user written equation, and then it is formatted as specified ...
Judgeship asked 25/1, 2019 at 14:45

3

I have a Spring Boot restful API service that returns a Java object in its response which is translated into json. One of the Java object properties is a 'Java.time.Instant'. How should I transla...
Nonconformity asked 6/7, 2017 at 10:1

2

Solved

I want to convert string date format into java.time.Instant I am getting exception while parsing date. java.lang.IllegalArgumentException: Too many pattern letters: s I am using below code for...
Available asked 18/8, 2018 at 16:34

5

Solved

I have a Java Set that I give information to: Set<myData> dataLocations = getData(location); I would like to sort this Set I have tried a sortedSet and couldn't get it to work, so I tried ...
Boreas asked 13/7, 2018 at 17:26

2

Solved

I have this code that generates a date and time, ZoneId z = ZoneId.of( "Africa/Nairobi" ); Instant instant = Instant.now(); ZonedDateTime zdt = instant.atZone(z); return zdt.toString(); ...
Herv asked 19/3, 2018 at 6:45

1

Solved

I am new in Mapstruct. I have a model object which includes LocalDateTime type field. DTO includes Instant type field. I want to map LocalDateTime type field to Instant type field. I have TimeZone ...

2

Solved

Classes as LocalDateTime from the package java.time are value based classes. If I have an entity using such an object as a field I run into the following "problem": Value based classes shouldn't be...
Provocation asked 18/12, 2017 at 9:22

1

Solved

In Joda, we can calculate years between 2 Datetime using Years.between(dateTime1, dateTime2); Is there any easy way to find years between 2 instants using the java.time API instead without much ...
Pecos asked 15/11, 2017 at 4:52

1

I trying to add few years to current time. My code looks like: // ten yeas ago int backYears = 10; Instant instant = ChronoUnit.YEARS.addTo(Instant.now(), -backYears); But I got an exception: j...
Lippi asked 10/11, 2017 at 23:6

1

Solved

With Java Date objects the easiest way to go was to store them as MySql DateTime objects (in UTC). With the switch to Instant this approach won't work anymore because MySQL DateTime does not offer ...
Kizer asked 9/11, 2017 at 9:58

3

Solved

I have following piece of code: String dateInString = "2016-09-18T12:17:21:000Z"; Instant instant = Instant.parse(dateInString); ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("Europe/Kie...
Maritime asked 10/2, 2017 at 20:13

2

I have a Spring boot 1.4.x application that uses the starter jpa in combination with H2/Postgresql. I have an entity that stores a date as an Instant (with Instant.now(), based on Java 8: What'...
Gravois asked 28/9, 2016 at 22:2

2

Solved

I have a pojo which has a filed type as Instant. I want to set the Instant getting it from TimsStamp. Would it be possible? For example: I have a java.sql.Timestamp which I want to conve...
Draughtboard asked 14/7, 2016 at 3:47

© 2022 - 2024 — McMap. All rights reserved.