v1.2.0.1-beta1

Description

Date prototype extension methods

Public Member Functions

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

Static Public Member Functions

Date fromLocaleDateString (locale, dateString, format)
 
Date fromLocaleString (locale, dateTimeString, format)
 
Date fromLocaleTimeString (locale, timeString, format)
 

Member Function Documentation

◆ clone()

Date clone ( )

Creates a deep copy of Date object.

◆ addSeconds()

Date addSeconds (   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 (   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 (   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 (   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 (   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 (   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 (   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 (   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(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,
  dateString,
  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, dateTimeString, format)
Converts the date string dateTimeString to a Date object using given locale and format.
See also
locale(), Locale

◆ fromLocaleString()

Date fromLocaleString (   locale,
  dateTimeString,
  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,
  timeString,
  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, timeString, format)
Converts the date string timeString to a Date object using given locale and format.
See also
locale(), Locale

◆ toLocaleDateString()

string toLocaleDateString (   locale,
  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, 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,
  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, 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,
  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, format)
Converts the Date to a string containing the time suitable for the specified locale in the specified ...
See also
locale(), Locale