Get to know MDN better
Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
O método setYear() atribui o ano para a data especificada de acordo com o horário local. Devido setYear() não colocar o anos cheios ("problema do ano 2000"), ele não é mais utilizado e foi substituído pelo método setFullYear().
Um inteiro.
O número de milissegundos entre 1 de Janeiro de 1970 00:00:00 UTC e a data atualizada.
Se yearValue é um número entre 0 e 99 (inclusivo), então o ano para dateObj é atribuido para 1900 + yearValue. Caso contrário, o ano para dateObj é atribuido para yearValue.
As duas primeiras linhas atribuem o ano para 1996. O terceiro atribui o ano para 2000.
| ECMAScript® 2027 Language Specification # sec-date.prototype.setyear |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 8 de nov. de 2023 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.