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

# Date

> Methods that jComponent adds to Date.prototype for formatting dates and calculating with them.

jComponent adds these methods to `Date.prototype`. Month and day names come from the global arrays `MONTHS` and `DAYS`, which the [Localization](../../guides/localization/) guide covers, and the default format is set in [DEF](../def/). Text is converted to a date with [parseDate()](../string/#parsedate).

## API

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

Type: `method`

Returns a new date moved by an amount of time.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | The unit, or the whole amount as text. |
| `value` | `Number` | no |  | The amount of the unit. |

Returns: `Date` A new date.

The original date is not changed. The amount is written as one text, such as `'2 days'`, or as a unit and a number. A negative number moves the date back.

| Unit | Accepted names |
| --- | --- |
| Seconds | `s`, `ss`, `sec`, `second`, `seconds` |
| Minutes | `m`, `mm`, `min`, `minute`, `minutes` |
| Hours | `h`, `hh`, `hour`, `hours` |
| Days | `d`, `dd`, `day`, `days` |
| Weeks | `w`, `ww`, `week`, `weeks` |
| Months | `M`, `MM`, `month`, `months` |
| Years | `y`, `yy`, `yyyy`, `year`, `years` |

Example: Move a date
```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`

Writes the date as text.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `String` | no | `DEF.dateformat` | The format of the output. |
| `utc` | `Boolean` | no |  | Writes the date in UTC. |

Returns: `String` The formatted date.

Without `format`, the method uses `DEF.dateformat`, which is `yyyy-MM-dd` by default. A format in the form `[key]` is read from `ENV()`. With `utc`, or when `DEF.dateformatutc` is `true`, the date is written in UTC. Use `date.format('iso', true)` for an ISO 8601 text.

| Token | Output for 18 November 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` (ISO week, two digits) |
| `w` | `47` (ISO week) |
| `a` | `PM` |

Every token letter is replaced wherever it appears, and a format cannot contain an apostrophe, so write literal words outside the format.

Example: Date formats
```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: UTC output
```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: Default format
```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`

Returns the same date.

Returns: `Date` The same date object.

Strings, numbers and dates all have a `parseDate()` method, so a value of any of these types can be converted without checking its type.

Example: Convert any value
```js
var date = new Date(2026, 10, 18);
date.parseDate() === date; // true
```

### date.toNumber([format])

Type: `method`

Writes the date as a number.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `String` | no | `'yyyyMMdd'` | A [format()](#format) layout that contains only digits. |

Returns: `Number` The date as a number.

The number is useful for comparing dates.

Example: Date as a number
```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`

Shifts the date by the time zone offset, so its local fields show the UTC time.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `ticks` | `Boolean` | no |  | Use `true` to get the milliseconds in place of a `Date`. |

Returns: `Date or Number` The shifted date, or its milliseconds.

Example: Shift to 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
```
