196 questions
4 votes
1 answer
577 views
What is the difference between withLocale() and localizedBy() in Java DateTimeFormatter?
DateTimeFormatter Java 8 introduced a modern date and time API with new types like LocalDate available in java.time.* package. It also provided a new DateTimeFormatter class for formatting (generating ...
-1 votes
1 answer
163 views
DateTimeFormatter with "yyyy-MM-dd HH:mm:ss" parses into LocalDateTime with missing seconds [duplicate]
I'm updating my code to use java.time.format.DateTimeFormatter instead of java.text.SimpleDateFormat and now a test fails which didn't before. When I parse the String 2010-12-31 00:00:00 , which in my ...
1 vote
0 answers
40 views
Inconsistent UWP DateTimeFormatter output for similar patterns with en-US culture
I'm using Windows.Globalization.DateTimeFormatting.DateTimeFormatter in a UWP app with the culture set to "en-US". I noticed inconsistent formatting between two similar patterns. Scenario: ...
4 votes
3 answers
203 views
Why does parsing with this DateTimeFormatter throw an exception?
Both of these DateTimeFormatters are nearly identical, however only the second one throws an exception. Both of these patterns are valid as far as I can tell. Why does changing minWidth cause parsing ...
-3 votes
2 answers
184 views
Does Instant.MAX need to be manually formatted? [closed]
DateTimeFormatter fails on valid Instants. How it is meant to format those below and above LocalDateTime.MIN and LocalDateTime.MAX? Manually? DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"...
1 vote
1 answer
92 views
Is DateTimeFormatter missing ofYearMonth() method?
Is DateTimeFormatter missing ofYearMonth() method? It has ofLocalizedDateTime() ofLocalizedDate() ofLocalizedTime() If using ofPattern(), it is not locale sensitive.
2 votes
1 answer
244 views
Is there any pattern to format and parse periods in a day, such as 'in the morning', 'in the afternoon' or 'at night'?
I want to express periods in the day, such as in the morning, in the afternoon, or at night, not just AM or PM. Is there any pattern in java.time API to format and parse periods in a day, such as in ...
0 votes
1 answer
86 views
DateTimeFormatter abbrevation [closed]
DateTime Formatter shows (GMT-8:00) instead of PST Date date = new Date(2024,11,23); ZoneId zone = ZoneId.of("US/Pacific"); DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("...
0 votes
1 answer
65 views
Elasticsearch Datetime Mapping for localized zone-offset in Brackets
I have an index in Elasticsearch that needs to take datetime formats in the following variations: 08/23/2023 8:00:00 PM(UTC+0) 2023-08-23T20:00:00+0000 I can't get an Elasticsearch mapping for the ...
5 votes
1 answer
508 views
Does Java's DateTimeFormatter allow lenient parsing for fractional seconds?
I am currently working with Java's DateTimeFormatter to parse ISO 8601 formatted timestamps, particularly those containing fractional seconds. While experimenting with different timestamp formats, I ...
2 votes
1 answer
111 views
DateTimeParseException for LocalDateTime object despite having the format mapped
I have a Java 8 application that has to accept any number of date and time formats from a user. Obviously that yields an exhaustive list, as there are many ways to write a date and time. For locale ...
-3 votes
1 answer
116 views
LocalDateTime Conversion [duplicate]
I am trying to convert current date and time with the help of LocalDateTime java class and then trying to store it in Database table column having Date datatype. Below is the code , i am trying to ...
2 votes
0 answers
158 views
LocalDate.parse does not validate leap years
DateTimeFormatter formatters = DateTimeFormatter.ofPattern("uuuu-MM-dd"); endDate = LocalDate.parse(endDateString, formatters); Why does the above code not throw exceptions for leap years? ...
2 votes
1 answer
122 views
DateTimeFormatter offset O
I've been looking around but can't find any example usage of offset O in the timestamp schema as described in https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html. From ...
-1 votes
2 answers
149 views
Formatting a String to a LocalDateTime
I know this has been asked before, but I still have an error after looking at all the solutions. I'm trying to parse a String to a LocalDateTime using a DateTimeFormatter. This is my code: import java....