I'm working on a ReasonReact project and I need to get the current year with the Js.Date module
I created a function to get a range between two years, so I need to pass the current year as the second parameter
let rangeYears = (startedYear, currentYear) =>
Belt_Array.range(startedYear, currentYear) ->
Array.to_list
|> List.map(
year => FormFieldSelect.{label: Js.Int.toString(year), value: `Int(year)}
)
You can instantiate a new Date type and use getFullYear.
let date = Js.Date.make()
let year = date->Js.Date.getFullYear
or, one-liner
let year = Js.Date.(make()->getFullYear)