Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Day of Week

Numbers, Dates & Timersmedium

Course · Section 12: Numbers, Dates, Intl and Timers · Lecture 186: Creating Dates

Implement `dayOfWeek(iso)` returning the UTC day of week (0 for Sunday through 6 for Saturday) for an ISO date string.

Sample tests

Input: dayOfWeek("2024-01-07")
Output: 0
Input: dayOfWeek("2024-01-08")
Output: 1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • getDay uses local time, which can differ from UTC near midnight.
Approach & explanation (try first)

getUTCDay reads the weekday in UTC, where 0 is Sunday.

Loading...
⌘/Ctrl + Enter

Run your code to see results.