java.time

What pattern of datetimeformat is needed for DateTimeFormatter to parse JAN01/2020? [duplicate]

不羁的心 提交于 2021-01-05 06:38:13
问题 This question already has an answer here : Why pattern of datetimeformat is needed to avoid this causing a DateTimeParseException? [duplicate] Java 8 DateTimeFormatter for month in all CAPS not working [duplicate] (1 answer) Closed 7 months ago . I'm being passed a date in ths format - "JAN01/2020" but I can't seem to find the DateTimeFormatter pattern for it. I tried these (as well as several others) but they're resulting in DateTimeParseException - DateTimeFormatter.ofPattern("MMMd/YYYY")

What pattern of datetimeformat is needed for DateTimeFormatter to parse JAN01/2020? [duplicate]

女生的网名这么多〃 提交于 2021-01-05 06:37:26
问题 This question already has an answer here : Why pattern of datetimeformat is needed to avoid this causing a DateTimeParseException? [duplicate] Java 8 DateTimeFormatter for month in all CAPS not working [duplicate] (1 answer) Closed 7 months ago . I'm being passed a date in ths format - "JAN01/2020" but I can't seem to find the DateTimeFormatter pattern for it. I tried these (as well as several others) but they're resulting in DateTimeParseException - DateTimeFormatter.ofPattern("MMMd/YYYY")

How to convert from Instant to LocalDate

最后都变了- 提交于 2020-06-24 08:09:28
问题 I have an Instant coming from a source that should, according to the spec, be a LocalDate, but don't see any methods in LocalDate for the conversion. What is the best way to do this? 回答1: LocalDate.ofInstant(...); I believe was added in Java 9. LocalDateTime has that method in Java 8. yourInstant.atZone(yourZoneId).toLocalDate(); Will work with earlier versions for LocalDate... 回答2: Other answers provided the mechanics for the transformation, but I wanted to add some background on the meaning

Why is adding weeks to java.time.Instant not supported?

爷,独闯天下 提交于 2020-02-15 07:52:29
问题 The following piece of code: Instant inFourWeeks = Instant.now().plus(4L, ChronoUnit.WEEKS); Throws an exception: java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Weeks Why are weeks unsupported? I understand why months and years are not supported, because their duration in smaller units may vary. But a week has constant duration (7 days) and I can achieve the same by writing: Instant inFourWeeks = Instant.now().plus(4L * 7L, ChronoUnit.DAYS); 回答1: It throws

CodecConfigurationException when saving ZonedDateTime to MongoDB with Spring Boot >= 2.0.1.RELEASE

拟墨画扇 提交于 2020-01-28 10:34:15
问题 I was able to reproduce my problem with a minimal modification of the official Spring Boot guide for Accessing Data with MongoDB, see https://github.com/thokrae/spring-data-mongo-zoneddatetime. After adding a java.time.ZonedDateTime field to the Customer class, running the example code from the guide fails with a CodecConfigurationException: Customer.java: public String lastName; public ZonedDateTime created; public Customer() { output: ... Caused by: org.bson.codecs.configuration

SimpleDateFormat not parsing time correctly [duplicate]

♀尐吖头ヾ 提交于 2020-01-16 18:10:07
问题 This question already has answers here : Changing Java Timestamp format causes a change of the timestamp (2 answers) Java / convert ISO-8601 (2010-12-16T13:33:50.513852Z) to Date object (4 answers) Date object SimpleDateFormat not parsing timestamp string correctly in Java (Android) environment (6 answers) Closed 11 months ago . This is happening with one (probably more) datetime where the time part is totally wrong in a parse. The code: import java.text.*; import java.util.*; public class

SimpleDateFormat not parsing time correctly [duplicate]

▼魔方 西西 提交于 2020-01-16 18:09:25
问题 This question already has answers here : Changing Java Timestamp format causes a change of the timestamp (2 answers) Java / convert ISO-8601 (2010-12-16T13:33:50.513852Z) to Date object (4 answers) Date object SimpleDateFormat not parsing timestamp string correctly in Java (Android) environment (6 answers) Closed 11 months ago . This is happening with one (probably more) datetime where the time part is totally wrong in a parse. The code: import java.text.*; import java.util.*; public class

What is the equivalent of Calendar.roll in java.time?

不想你离开。 提交于 2020-01-11 09:55:30
问题 I was studying the old Calendar API to see how bad it was, and I found out that Calendar has a roll method. Unlike the add method, roll does not change the values of bigger calendar fields. For example, the calendar instance c represents the date 2019-08-31. Calling c.roll(Calendar.MONTH, 13) adds 13 to the month field, but does not change the year, so the result is 2019-09-30. Note that the day of month changes, because it is a smaller field. Related I tried to find such a method in the

java.time.LocalDate vs Instant for a 'business date'

爱⌒轻易说出口 提交于 2020-01-06 06:50:01
问题 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 2 June 2019' in the US - and ordering within the 'day' is equally irrelevant. All dates will be today, or prior dates. My obvious answer is that this is a LocalDate . However someone else has suggested this would be better represented as an Instant of 2019-06-03T00:00:00.000Z . Apart from the

java.time.LocalDate vs Instant for a 'business date'

邮差的信 提交于 2020-01-06 06:49:36
问题 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 2 June 2019' in the US - and ordering within the 'day' is equally irrelevant. All dates will be today, or prior dates. My obvious answer is that this is a LocalDate . However someone else has suggested this would be better represented as an Instant of 2019-06-03T00:00:00.000Z . Apart from the