---
title: Date
project: jComponent V20
version: 20.015
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-015/reference/date/
updated: 2026-11-18T13:58:19.462Z
---

# Date

> Methods that jComponent adds to Date.prototype for date arithmetic, formatting and UTC conversion.

jComponent adds these methods to every date. The default format is set in [DEF](../def/), text is converted to a date with [parseDate()](../string/), and the month and day names come from the global arrays `MONTHS` and `DAYS`.

## API

### Date.add(value)

Type: `method`

Returns a new date moved by a duration.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `String` | yes |  | The duration. |

Returns: `Date` A new date. The original date does not change.

The value is a number, a space and a unit. A negative number moves the date back, and the number can be a `[key]` phrase set with [ENV()](../globals/). An unknown unit returns an unchanged copy.

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

Example: Moving a date
```js
var date = new Date(2026, 0, 15, 10, 0, 0);
console.log(date.add('1 day').format('yyyy-MM-dd')); // 2026-01-16
console.log(date.add('-1 month').format('yyyy-MM-dd')); // 2025-12-15
console.log(date.add('2 hours').format('HH:mm')); // 12:00
console.log(date.add('30 m').format('HH:mm')); // 10:30
console.log(date.format('yyyy-MM-dd HH:mm')); // 2026-01-15 10:00
```

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

Type: `method`

Writes the date as text.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `String` | no | `DEF.dateformat` | The layout of the text. |
| `utc` | `Boolean` | no | `false` | `true` writes the date in UTC. |

Returns: `String` The formatted date.

Every token in `format` is replaced, so other letters that match a token cannot be used as literal text.

| Token | Output | Example |
| --- | --- | --- |
| `yyyy`, `YYYY` | Full year | `2026` |
| `yy`, `YY` | Two-digit year | `26` |
| `MMMM` | Month name | `November` |
| `MMM` | First three letters of the month | `Nov` |
| `MM` | Month with two digits | `11` |
| `M` | Month | `11` |
| `dddd`, `DDDD` | Day name | `Sunday` |
| `ddd`, `DDD` | First two letters of the day in uppercase | `SU` |
| `dd`, `DD` | Day with two digits | `08` |
| `d`, `D` | Day | `8` |
| `HH`, `hh` | Hours with two digits (0 to 23) | `15` |
| `H`, `h` | Hours (0 to 23) | `15` |
| `mm` | Minutes with two digits | `04` |
| `m` | Minutes | `4` |
| `ss` | Seconds with two digits | `05` |
| `s` | Seconds | `5` |
| `ww` | ISO week with two digits | `45` |
| `w` | ISO week | `45` |
| `a` | `AM` or `PM` | `PM` |

Start the format with `!` to write the hours on a 12-hour clock, from 1 to 12, for example `!hh:mm a`. A `[key]` format uses the format set with [ENV()](../globals/).

`format('iso')` returns the ISO 8601 date in UTC, the same as `toISOString()`, and an empty string for an invalid date. Setting `DEF.dateformatutc` to `true` makes every call use UTC.

Example: Layouts
```js
var date = new Date(2026, 10, 8, 15, 4, 5);
console.log(date.format()); // 2026-11-08
console.log(date.format('dd.MM.yyyy HH:mm')); // 08.11.2026 15:04
console.log(date.format('dddd, d MMMM yyyy')); // Sunday, 8 November 2026
console.log(date.format('MMM yy')); // Nov 26
console.log(date.format('ww')); // 45
```

Example: UTC output
```js
var date = new Date(Date.UTC(2026, 10, 8, 15, 4, 5));
console.log(date.format('yyyy-MM-dd HH:mm', true)); // 2026-11-08 15:04
console.log(date.format('iso')); // 2026-11-08T15:04:05.000Z
```

Example: 12-hour clock and environment formats
```js
var date = new Date(2026, 10, 8, 12, 30);
console.log(date.format('!hh:mm a')); // 12:30 PM

ENV('short', 'dd.MM.');
console.log(date.format('[short]')); // 08.11.
ENV('short', 'MM/dd');
console.log(date.format('[short]')); // 11/08
```

### Date.toUTC([ticks])

Type: `method`

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

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `ticks` | `Boolean` | no | `false` | `true` returns the timestamp in milliseconds in place of a `Date`. |

Returns: `Date or Number` The converted date, or its timestamp.

Example: Converting to UTC
```js
var date = new Date(Date.UTC(2026, 10, 8, 15, 4));
console.log(date.toUTC().format('yyyy-MM-dd HH:mm')); // 2026-11-08 15:04
console.log(date.toUTC(true) === date.toUTC().getTime()); // true
```
