Skip to content
Advertisement

Tag: java-time

Java convert DateTime from “yyyy-MM-dd HH:mm:ss.SSSSSSS” to “yyyy-MM-dd HH:mm:ss.S” or from “yyyy-MM-dd HH:mm:ss.SSSSSSS” to “yyyy-MM-dd HH:mm:ss.SSS”

Java 11 I want to convert the date in “yyyy-MM-dd HH:mm:ss.SSSSSSS” to either “yyyy-MM-dd HH:mm:ss.S” or “yyyy-MM-dd HH:mm:ss.SSS” based on milliseconds value. If milliseconds are all zeros, then I just want single zero but if it is non-zero value then I want just value omitting trailing zeros. Example : Input : 2021-03-10 16:37:02.4230000 => Desired Output : 2021-03-10 16:37:02.423 Input : 2021-03-10 16:39:51.0000000

Create a DateTimeFormater with an Optional Section at Beginning

I have timecodes with this structure hh:mm:ss.SSS for which i have a own Class, implementing the Temporal Interface. It has the custom Field TimecodeHour Field allowing values greater than 23 for hour. I want to parse with DateTimeFormatter. The hour value is optional (can be omitted, and hours can be greater than 24); as RegEx (d*dd:)?dd:dd.ddd For the purpose of

Unable to obtain LocalDate from TemporalAccessor for week based string

I’m trying to parse a simple string in the format “YYYYww” (e.g. 201901) into a LocalDate, but none of my attempts succeed. I attempted to parse it by simply using the pattern “YYYYww” and also through manually appending the values to the FormatterBuilder. Since my input string does not contain a day, I also configured the formatter to default to

DateTimeFormatter – Strict vs Lenient unexpected behaviour

I have some text that is only being parsed by a DateTimeFormatter when the parse style is Strict – and not when it’s Lenient. This seems like the opposite behaviour to what I’d expect? Example: Output: Answer Having posted this as a bug – https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8228353 I got the following reply: According to DateTimeFormatterBuilder’s spec, appendPattern(“yy”) translates to appendValueReduced(ChronoField.YEAR_OF_ERA, 2, 2000),

Advertisement