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 (ECMA-262)
The definition of 'Date.prototype.getFullYear' in that specification.
Living Standard  

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 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100

Legend

Full support  
Full support

Lihat juga