---
title: Date
project: jComponent V19
version: 19.194
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/jcomponent-v19/19-194/reference/date/
updated: 2026-11-18T13:58:29.465Z
---

# Date

> Metodi che jComponent aggiunge a Date.prototype per formattare le date e fare calcoli con esse.

jComponent aggiunge questi metodi a `Date.prototype`. I nomi di mesi e giorni provengono dagli array globali `MONTHS` e `DAYS`, trattati nella guida [Localizzazione](../../guides/localization/), e il formato predefinito si imposta in [DEF](../def/). Il testo viene convertito in data con [parseDate()](../string/#parsedate).

## API

### date.add(type, [value])

Type: `method`

Restituisce una nuova data spostata di una certa quantità di tempo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | L'unità, oppure l'intera quantità come testo. |
| `value` | `Number` | no |  | La quantità dell'unità. |

Returns: `Date` Una nuova data.

La data originale non viene modificata. La quantità si scrive come un unico testo, ad esempio `'2 days'`, oppure come unità e numero. Un numero negativo sposta la data indietro.

| Unità | Nomi accettati |
| --- | --- |
| Secondi | `s`, `ss`, `sec`, `second`, `seconds` |
| Minuti | `m`, `mm`, `min`, `minute`, `minutes` |
| Ore | `h`, `hh`, `hour`, `hours` |
| Giorni | `d`, `dd`, `day`, `days` |
| Settimane | `w`, `ww`, `week`, `weeks` |
| Mesi | `M`, `MM`, `month`, `months` |
| Anni | `y`, `yy`, `yyyy`, `year`, `years` |

Example: Sposta una data
```js
var date = new Date(2026, 10, 18, 14, 5, 9);
var f = 'yyyy-MM-dd HH:mm:ss';

date.add('1 day').format(f); // "2026-11-19 14:05:09"
date.add('-1 day').format(f); // "2026-11-17 14:05:09"
date.add('2 hours').format(f); // "2026-11-18 16:05:09"
date.add('min', 30).format(f); // "2026-11-18 14:35:09"
date.add('M', 2).format(f); // "2027-01-18 14:05:09"
date.add('2 weeks').format(f); // "2026-12-02 14:05:09"
date.format(f); // "2026-11-18 14:05:09"
```

### date.format([format], [utc])

Type: `method`

Scrive la data come testo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `String` | no | `DEF.dateformat` | Il formato dell'output. |
| `utc` | `Boolean` | no |  | Scrive la data in UTC. |

Returns: `String` La data formattata.

Senza `format`, il metodo usa `DEF.dateformat`, che per impostazione predefinita è `yyyy-MM-dd`. Un formato nella forma `[key]` viene letto da `ENV()`. Con `utc`, oppure quando `DEF.dateformatutc` è `true`, la data viene scritta in UTC. Usa `date.format('iso', true)` per ottenere un testo ISO 8601.

| Token | Output per il 18 novembre 2026, 14:05:09 |
| --- | --- |
| `yyyy`, `YYYY` | `2026` |
| `yy`, `YY` | `26` |
| `MMMM` | `November` |
| `MMM` | `Nov` |
| `MM` | `11` |
| `M` | `11` |
| `dddd`, `DDDD` | `Wednesday` |
| `ddd`, `DDD` | `WE` |
| `dd`, `DD` | `18` |
| `d`, `D` | `18` |
| `HH`, `hh` | `14` |
| `H`, `h` | `14` |
| `mm` | `05` |
| `m` | `5` |
| `ss` | `09` |
| `s` | `9` |
| `ww` | `47` (settimana ISO, due cifre) |
| `w` | `47` (settimana ISO) |
| `a` | `PM` |

Ogni lettera di un token viene sostituita ovunque compaia e un formato non può contenere un apostrofo, quindi scrivi le parole letterali fuori dal formato.

Example: Formati di data
```js
var date = new Date(2026, 10, 18, 14, 5, 9);

date.format(); // "2026-11-18"
date.format('dd.MM.yyyy HH:mm:ss'); // "18.11.2026 14:05:09"
date.format('dddd, d MMMM yyyy'); // "Wednesday, 18 November 2026"
date.format('MMM yy'); // "Nov 26"
date.format('HH:mm a'); // "14:05 PM"
date.format('yyyy-ww'); // "2026-47"
```

Example: Output in UTC
```js
var date = new Date(Date.UTC(2026, 10, 18, 13, 5, 9, 7));

date.format('HH:mm', true); // "13:05"
date.format('iso', true); // "2026-11-18T13:05:09.007Z"
```

Example: Formato predefinito
```js
var date = new Date(2026, 10, 18);

DEF.dateformat = 'dd/MM/yyyy';
date.format(); // "18/11/2026"
DEF.dateformat = 'yyyy-MM-dd';

ENV('short', 'dd.MM.');
date.format('[short]'); // "18.11."
```

### date.parseDate()

Type: `method`

Restituisce la stessa data.

Returns: `Date` Lo stesso oggetto data.

Stringhe, numeri e date hanno tutti un metodo `parseDate()`, quindi puoi convertire un valore di uno qualsiasi di questi tipi senza controllarne il tipo.

Example: Converti un valore qualsiasi
```js
var date = new Date(2026, 10, 18);
date.parseDate() === date; // true
```

### date.toNumber([format])

Type: `method`

Scrive la data come numero.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `String` | no | `'yyyyMMdd'` | Un layout di [format()](#format) che contiene solo cifre. |

Returns: `Number` La data come numero.

Il numero è utile per confrontare le date.

Example: Data come numero
```js
var date = new Date(2026, 10, 18, 14, 5);

date.toNumber(); // 20261118
date.toNumber('yyyyMM'); // 202611
date.toNumber('yyyyMMddHHmm'); // 202611181405
```

### date.toUTC([ticks])

Type: `method`

Sposta la data del valore del fuso orario, così i suoi campi locali mostrano l'ora UTC.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `ticks` | `Boolean` | no |  | Usa `true` per ottenere i millisecondi al posto di un `Date`. |

Returns: `Date or Number` La data spostata o i relativi millisecondi.

Example: Sposta in UTC
```js
var date = new Date(Date.UTC(2026, 10, 18, 13, 5));

date.toUTC().getHours(); // 13
date.toUTC(true) === date.getTime() + date.getTimezoneOffset() * 60000; // true
```
