v1.3.0.0

Description

Date prototype extension methods

Public Member Functions

Date clone ()
 
Date addSeconds (number seconds)
 
Date addMinutes (number seconds)
 
Date addHours (number seconds)
 
Date addDays (number days)
 
Date addMonths (number months)
 
Date addYears (number years)
 
Date compareToDate (Date otherDate)
 
string format (string format)
 
string toLocaleDateString (Locale locale, string format)
 
string toLocaleString (Locale locale, string format)
 
string toLocaleTimeString (Locale locale, string format)
 

Static Public Member Functions

Date fromLocaleDateString (Locale locale, string dateString,< string|number > format)
 
Date fromLocaleString (Locale locale, string dateTimeString,< string|number > format)
 
Date fromLocaleTimeString (Locale locale, string timeString,< string|number > format)
 

Member Function Documentation

◆ clone()

Date clone ( )

Creates a deep copy of Date object.

◆ addSeconds()

Date addSeconds ( number  seconds)

Adds seconds to current date and returns new Date object. seconds can be negative to subtract from current time and can be in any integer value range.

◆ addMinutes()

Date addMinutes ( number  seconds)

Adds minutes to current date and returns new Date object. minutes can be negative to subtract from current time and can be in any integer value range.

◆ addHours()

Date addHours ( number  seconds)

Adds hours to current date and returns new Date object. hours can be negative to subtract from current time and can be in any integer value range.

◆ addDays()

Date addDays ( number  days)

Adds days to current date and returns new Date object. days can be negative to subtract from current date and can be in any integer value range.

◆ addMonths()

Date addMonths ( number  months)

Adds months to current date and returns new Date object. months can be negative to subtract from current date and can be in any integer value range.

◆ addYears()

Date addYears ( number  years)

Adds years to current date and returns new Date object. years can be negative to subtract from current date and can be in any integer value range.

◆ compareToDate()

Date compareToDate ( Date  otherDate)

Compares this Date to otherDate based only on the year, month and day parts, ignoring time part. Returns -1 if otherDate is earlier than this date, 0 if the dates match, and 1 if otherDate is later than this date.

◆ format()

string format ( string  format)

Formats this date according the specified .NET-style format string.

This function emulates the .NET DateTime.ToString() method.

For example:

console.log(new Date().format("yyyy MMM DD @ HH:mm::ss")); // Prints: "2022 Jan 05 @ 22:03:55"
Date prototype extension methods
string format(string format)
Formats this date according the specified .NET-style format string.

See formatting string reference at https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#table-of-format-specifiers

See also
String.format(), toLocaleString(), toLocaleDateString(), toLocaleTimeString()

◆ fromLocaleDateString()

Date fromLocaleDateString ( Locale  locale,
string  dateString,
< string|number >  format 
)
static

Converts the date string dateString to a Date object using given locale and format.

Parameters
localeA Locale object, obtained with the global locale() method.
dateStringThe input string to parse
formatA Locale format constant or string format specifier.

If format is not specified, Locale.LongFormat will be used.
If locale is not specified, the default locale will be used.

The following example shows a datetime being parsed from a datetime string in a certain format using the default locale

var dateString = "Freitag 2022-12-09";
var date = Date.fromLocaleString(locale("de_DE"), dateString, "dddd yyyy-MM-dd");
Date fromLocaleString(Locale locale, string dateTimeString,< string|number > format)
Converts the date string dateTimeString to a Date object using given locale and format.
See also
locale(), Locale

◆ fromLocaleString()

Date fromLocaleString ( Locale  locale,
string  dateTimeString,
< string|number >  format 
)
static

Converts the date string dateTimeString to a Date object using given locale and format.

Parameters
localeA Locale object, obtained with the global locale() method.
dateTimeStringThe input string to parse
formatA Locale format constant or string format specifier.

If format is not specified, Locale.LongFormat will be used.
If locale is not specified, the default locale will be used.

The following example shows a datetime being parsed from a datetime string in a certain format using the default locale

var dateTimeString = "Freitag 2022-12-09 22:56:06";
var date = Date.fromLocaleString(locale(), dateTimeString, "dddd yyyy-MM-dd hh:mm:ss");
See also
locale(), Locale

◆ fromLocaleTimeString()

Date fromLocaleTimeString ( Locale  locale,
string  timeString,
< string|number >  format 
)
static

Converts the date string timeString to a Date object using given locale and format.

Parameters
localeA Locale object, obtained with the global locale() method.
timeStringThe input string to parse
formatA Locale format constant or string format specifier.

If format is not specified, Locale.LongFormat will be used.
If locale is not specified, the default locale will be used.

The following example shows a datetime being parsed from a datetime string in a certain format using the German locale:

Date date = Date.fromLocaleTimeString(locale("de_DE"), "22:56:06", "HH:mm:ss");
Date fromLocaleTimeString(Locale locale, string timeString,< string|number > format)
Converts the date string timeString to a Date object using given locale and format.
See also
locale(), Locale

◆ toLocaleDateString()

string toLocaleDateString ( Locale  locale,
string  format 
)

Converts the Date to a string containing the date suitable for the specified locale in the specified format.

Parameters
localeA Locale object, obtained with the global locale() method.
formatA Locale format constant or string format specifier.

If format is not specified, Locale.LongFormat will be used.
If locale is not specified, the default 'locale()` will be used.

The following example shows the current date formatted for the German locale:

new Date().toLocaleDateString(locale("de_DE"))
// "Freitag, 9. Dezember 2022"
string toLocaleDateString(Locale locale, string format)
Converts the Date to a string containing the date suitable for the specified locale in the specified ...
See also
locale(), Locale

◆ toLocaleString()

string toLocaleString ( Locale  locale,
string  format 
)

Converts the Date to a string containing the date and time suitable for the specified locale in the specified format.

Parameters
localeA Locale object, obtained with the global locale() method.
formatA Locale format constant or string format specifier.

If format is not specified, Locale.LongFormat will be used. If locale is not specified, the default 'locale()` will be used.

The following example shows the current date and time formatted for the German locale:

new Date().toLocaleString(locale("de_DE", dddd, d. MMMM yyyy HH:mm:ss))
// "Freitag, 9. Dezember 2022 09:05:27"
string toLocaleString(Locale locale, string format)
Converts the Date to a string containing the date and time suitable for the specified locale in the s...
See also
locale(), Locale

◆ toLocaleTimeString()

string toLocaleTimeString ( Locale  locale,
string  format 
)

Converts the Date to a string containing the time suitable for the specified locale in the specified format.

Parameters
localeA Locale object, obtained with the global locale() method.
formatA Locale format constant or string format specifier.

If format is not specified, Locale.LongFormat will be used. If locale is not specified, the default locale will be used.

The following example shows the current date and time formatted for the German locale:

new Date().toLocaleTimeString(locale("de_DE"))
// "19:05:27 Eastern Standard Time"
string toLocaleTimeString(Locale locale, string format)
Converts the Date to a string containing the time suitable for the specified locale in the specified ...
See also
locale(), Locale