CoffeeScript Date - getFullYear ()

Descrizione

Il getFullYear()restituisce l'anno della data specificata in base all'ora locale. Il valore restituito dagetFullYear()è un numero assoluto. Per le date comprese tra gli anni 1000 e 9999, getFullYear () restituisce un numero di quattro cifre, ad esempio 2008.

Sintassi

Di seguito è riportata la sintassi di getFullYear() metodo.

getFullYear()

Esempio

L'esempio seguente mostra l'utilizzo di getFullYear()metodo in CoffeeScript. Salva questo codice in un file con nomedate_getfullyear.coffee.

dt = new Date "February 19, 2016 23:15:00"
console.log "The year the current date object is : " + dt.getFullYear()

Apri il command prompt e compila il file .coffee come mostrato di seguito.

c:\> coffee -c date_getfullyear.coffee

Durante la compilazione, ti dà il seguente JavaScript.

// Generated by CoffeeScript 1.10.0
(function() {
  var dt;

  dt = new Date("February 19, 2016 23:15:00");

  console.log("The year the current date object is : " + dt.getFullYear());

}).call(this);

Ora apri il file command prompt di nuovo ed eseguire il file CoffeeScript come mostrato di seguito.

c:\> coffee date_getfullyear.coffee

All'esecuzione, il file CoffeeScript produce il seguente output.

The year the current date object is : 2016