Establecer fecha de JavaScriptUTCFullYear()
Ejemplo
Establezca el año en 2015:
const d = new Date();
d.setUTCFullYear(2015);
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
El método setUTCFullYear() establece el año de un objeto de fecha, según UTC.
notas
UTC (Universal Time Coordinated) es la hora establecida por el estándar de hora mundial.
La hora UTC es la misma que la hora GMT (hora del meridiano de Greenwich).
Compatibilidad con navegador
setUTCFullYear()
es una característica de ECMAScript1 (ES1).
ES1 (JavaScript 1997) es totalmente compatible con todos los navegadores:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Sintaxis
Date.setUTCFullYear(year, month, day)
Valores paramétricos
Parameter | Description |
---|---|
year | Required. A value representing the year, negative values are allowed |
month | Optional. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
Valor devuelto
Type | Description |
---|---|
Number | Milliseconds between the date object and midnight January 1 1970 |
Detalles técnicos
Versión de JavaScript: | ECMAscript 1 |
---|
Más ejemplos
Ejemplo 2
Establezca la fecha al 3 de noviembre de 2020, hora UTC:
const d = new Date();
d.setUTCFullYear(2020, 10, 3);
Ejemplo
Establezca la fecha en hace seis meses , hora UTC:
const d = new Date();
d.setUTCFullYear(d.getUTCFullYear, d.getUTCMonth() - 6);