Spanish Total.js
English
Documentation For AI agents
Contents

Date

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

.md GitHub
On this page

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

API

method

Date.add(value)

Returns a new date moved by a duration.
ParameterTypeDescription
value String 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(). An unknown unit returns an unchanged copy.

UnitAccepted names
Secondsseconds, second, sec, ss, s
Minutesminutes, minute, min, mm, m
Hourshours, hour, hh, h
Daysdays, day, dd, d
Weeksweeks, week, ww, w
Monthsmonths, month, MM, M
Yearsyears, year, yyyy, yy, y
Moving a date
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
method

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

Writes the date as text.
ParameterTypeDescription
format? String The layout of the text. Default: DEF.dateformat
utc? Boolean true writes the date in UTC. Default: false

Returns String The formatted date.

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

TokenOutputExample
yyyy, YYYYFull year2026
yy, YYTwo-digit year26
MMMMMonth nameNovember
MMMFirst three letters of the monthNov
MMMonth with two digits11
MMonth11
dddd, DDDDDay nameSunday
ddd, DDDFirst two letters of the day in uppercaseSU
dd, DDDay with two digits08
d, DDay8
HH, hhHours with two digits (0 to 23)15
H, hHours (0 to 23)15
mmMinutes with two digits04
mMinutes4
ssSeconds with two digits05
sSeconds5
wwISO week with two digits45
wISO week45
aAM or PMPM

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().

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.

Layouts
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
UTC output
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
12-hour clock and environment formats
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
method

Date.toUTC([ticks])

Moves the date by the time zone offset, so that its local fields show the UTC time.
ParameterTypeDescription
ticks? Boolean true returns the timestamp in milliseconds in place of a Date. Default: false

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

Converting to UTC
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
Made in Europe