A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear below:

Date.prototype.getYear() - JavaScript | MDN

Date.prototype.getYear()

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.

Resumo

O método getYear() retorna o ano especificado pela data de acordo com a hora local. Por conta do fato de que getYear() não retorna anos completos ("problema do ano 2000"), este método não é mais utilizado e foi substituido pelo método getFullYear().

Sintaxe Parâmetros

Nenhum.

Retorna

O método getYear() retorna o ano menos 1900; então:

Para levar em consideração anos antes e depois de 2000, você deve utilizar getFullYear() ao invés de getYear() para que o ano seja especificado por completo.

Retrocombatibilidade Comportamento em JavaScript 1.2 e anteriores

O método getYear() retorna um ano de 2 ou 4 dígitos:

Exemplos Exemplo: Anos entre 1900 e 1999

O segundo statement atribui o valor 95 à variável year.

var Xmas = new Date("December 25, 1995 23:15:00");
var year = Xmas.getYear(); // returns 95
Exemplo: Anos depois de 1999

O segundo statement atribui o valor 100 à variável year.

var Xmas = new Date("December 25, 2000 23:15:00");
var year = Xmas.getYear(); // returns 100
Exemplo: Anos antes de 1900

O segundo statement atribui o valor -100 à variável year.

var Xmas = new Date("December 25, 1800 23:15:00");
var year = Xmas.getYear(); // returns -100
Exemplo: Setando e recuperando um ano entre 1900 e 1999

O segundo statement atribui o valor 95 à variável year, representanto o ano 1995.

var Xmas.setYear(95);
var year = Xmas.getYear(); // returns 95
Especificações Compatibilidade com navegadores Veja também

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4