I am trying to get the week of the current month like so:
YearMonth
.from(Instant.now().atZone(ZoneId.of("UTC")))
.get(WeekFields.ISO.weekOfMonth())
But this throws
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: DayOfWeek
I can't seem to work out why I'm getting this exception, because I'm not doing anything with DayOfWeek. Any ideas?
You can't get the week of the current month using YearMonth. It only has year and month. Change
YearMonth
.from(Instant.now().atZone(ZoneId.of("UTC")))
.get(WeekFields.ISO.weekOfMonth())
to
LocalDate
.from(Instant.now().atZone(ZoneId.of("UTC")))
.get(WeekFields.ISO.weekOfMonth())
And I get
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With