Set the year to the given date.
Set the year to the given date.
// CommonJS
var setYear = require('date-fns/setYear')
// ES 2015 import setYear from 'date-fns/setYear'
// ESM
import { setYear } from 'date-fns'
setYear(date, year)
| Name | Description |
|---|---|
date |
the date to be changed |
year |
the year of the new date |
| Description |
|---|
|
the new date with the year set |
| Type | Description |
|---|---|
TypeError |
2 arguments required |
// Set year 2013 to 1 September 2014: const result = setYear(new Date(2014, 8, 1), 2013) //=> Sun Sep 01 2013 00:00:00
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/setYear