Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

477
Views
Java 8 Date API - Getting week of month throws UnsupportedTemporalTypeException: Unsupported field: DayOfWeek

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?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!