java-time Questions

12

Solved

Joda Time has a nice DateTimeUtils.setCurrentMillisFixed() to mock time. It's very practical in tests. Is there an equivalent in Java 8's java.time API?
Columbic asked 30/6, 2014 at 13:29

1

Solved

I'm trying to convert a Japanese date string to JapaneseDate. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("Gyy年MM月dd日") .withChronology(JapaneseChronology.INSTANCE) .withR...
Genni asked 7/11, 2021 at 0:27

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

3

Solved

I'm using a client library (third party, not mine, cannot change) which utilizes the ThreeTen date types. My project is Java 11 and uses Java 8 date types. What is the recommended way to convert Th...
Hemiterpene asked 21/1, 2020 at 14:54

6

Solved

I have a long timestamp 1499070300 (equivalent to Mon, 03 Jul 2017 16:25:00 +0800) but when I convert it to LocalDateTime I get 1970-01-18T16:24:30.300 Here's my code long test_timestamp = 14990...
Synesthesia asked 3/7, 2017 at 10:35

5

Is there an official list of zone names that are used for the following: zoneId = ZoneId.of("America/New_York") Or is it possible for java.time.ZoneId to generate the list itself that I can use?...
Pandybat asked 28/2, 2017 at 15:8

4

I'm attempting to read a JSON file using Jackson and store one of the fields that is stored as a epoch milliseconds as a Java Instant, however deserialization is not behaving as expected. Here is...
Pimple asked 18/8, 2017 at 18:22

7

Solved

I want to write a boolean valued function which returns true if the given LocalDateTime falls between two specific points in time, false otherwise. Specifically I want to have a LocalDateTime filt...
Emera asked 26/4, 2016 at 6:44

3

Solved

In Java 8, the Duration class offered the toDays method, returning a total number of days as a count of 24-hour chunks of time unrelated to calendar days. In Java 9, the Duration class gained handy...
Spiroid asked 29/3, 2021 at 20:25

2

Solved

I wonder is it possible to parse clock time hour:minute:second in Java 8? e.g. final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); final String str = "12:22:10"; final Lo...
Alphonso asked 5/10, 2016 at 9:24

4

Solved

Is there any difference between these: zonedDateTime.truncatedTo(ChronoUnit.DAYS); zonedDateTime.toLocalDate().atStartOfDay(zonedDateTime.getZone()); Any reason to prefer one against the other?...
Contribute asked 19/3, 2015 at 11:55

2

Solved

I have used DatePicker in javafx - JDK 8 and used HijrahChronology.INSTANCE - so that the date picker shows both the calendar - everything work good enough but I am having a difference of 1 day bet...
Jeaninejeanlouis asked 25/6, 2018 at 4:48

4

Solved

I created this wonderful static method yesterday, and it worked just fine - yesterday However, today it gives me this error. I guess it is from too many 0s before the Z. Can anyone recommend how ...
Mediator asked 28/9, 2015 at 14:58

5

Solved

The expression OffsetDateTime.parse("2016-08-24T18:38:05.507+0000") results in the following error: java.time.format.DateTimeParseException: Text '2016-08-24T18:38:05.507+0000' could not be pa...
Murky asked 24/8, 2016 at 22:14

17

Solved

Given today's time e.g. 2:24PM, how do I get it to round to 2:30PM? Similarly if the time was 2:17PM, how do I get it to round to 2:15PM?
Braque asked 24/8, 2010 at 6:24

2

Solved

I am writing a stock program that (so far) gets the data from "Markit on Demand" through a request such as this: http://dev.markitondemand.com/Api/v2/Quote/xml?symbol=aapl This returns th...
Phonation asked 20/7, 2014 at 15:1

4

Solved

I know there are questions relating to java.util.Date and Joda-Time. But after some digging, I couldn't find a thread about the differences between the java.time API (new in Java 8, defined by JSR ...
Roping asked 8/7, 2014 at 12:28

1

Solved

I recently answered some questions using LocalDate.atStartOfDay() and LocalDate.atTime(LocalTime.MIN). I was wondering why there is no LocalDate.atEndOfDay() or similar, so one has to use LocalDate...
Fiction asked 16/6, 2021 at 7:41

3

Solved

I got the following piece of code: ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaTimeModule()); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); String...
Farseeing asked 19/1, 2017 at 18:53

3

Solved

LocalDate in Java has two similar methods equals and isEqual. What's the difference between them? When do they output different results?
Carpophore asked 22/5, 2021 at 9:1

6

Solved

I need to be able to store a date (year/month/day) with no time component. It's an abstract concept of a date, such as a birthday - I need to represent a date in the year and not a particular insta...
Ocasio asked 12/11, 2008 at 22:8

4

Solved

I have a formatted date from sqllite database, to use this in a graph view I need to format it in a long number. The format is: 2012-07-11 10:55:21 how can I convert it to milliseconds?
Sprig asked 11/7, 2012 at 16:13

3

Solved

My program is parsing an input string to a LocalDate object. For most of the time the string looks like 30.03.2014, but occasionally it looks like 3/30/2014. Depending on which, I need to use a dif...
Afterword asked 6/5, 2014 at 7:39

7

Solved

What's the nicest way to parse a date that can be in one of the following formats "dd-MM-yyyy HH:mm" "dd/MM/yyyy HH:mm" "dd.MM.yyyy HH:mm" without creating 3 SimpleDateFormats and parsing ag...
Underbodice asked 18/9, 2009 at 9:23

2

Solved

I have a time A which should fall within 90 minutes range of timeB (before and after). Example: if timeB is 4:00 pm , time A should be between 2:30pm (-90) to 5:30pm (+90) Tried the following : ...
Discontinuity asked 25/10, 2017 at 21:29

© 2022 - 2024 — McMap. All rights reserved.