Date.prototype.getFullYear()

Metode getFullYear() mengembanlikan tahun dari tanggal yang dispesifikasi, mengikuti waktu lokal.

Gunakan metode ini ketimbang metode getYear().

Syntax

dateObj.getFullYear()

Nilai kembali

Angka yang berkorespondensi ke tahuny dari tanggal yang diberikan, mengikuti waktu lokal.

Deskripsi

Nilai yang dikembalikan oleh getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000.

Contoh

Menggunakan getFullYear()

Contoh ini menggassign nilai empat-digit dari tahun saat ini ke variabel year.

var today = new Date();
var year = today.getFullYear();

Spesifikasi

Spesifikasi Status Komen
ECMAScript 1st Edition (ECMA-262) Standard Definisi inisial. Diimplementasi di JavaScript 1.3.
ECMAScript 5.1 (ECMA-262)
The definition of 'Date.prototype.getFullYear' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Date.prototype.getFullYear' in that specification.
Standard  
ECMAScript Latest Draft (ECMA-262)
The definition of 'Date.prototype.getFullYear' in that specification.
Draft  

Kompatibilitas peramban

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
getFullYearChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support YesSafari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0nodejs Full support Yes

Legend

Full support  
Full support

Lihat juga