WorldDate library – a powerful and versatile JavaScript library for seamless date and time manipulation. This library offers a comprehensive set of functions designed to handle various aspects of date and time, ensuring accuracy and ease of use in a variety of applications.
-
Date Manipulation:
- Add or subtract milliseconds, seconds, minutes, hours, days, months, and years.
- Set specific date and time components.
-
Formatting and Parsing:
- Format dates in diverse representations.
- Parse dates back into WorldDate objects.
-
Time Zone Handling:
- Convert dates between different time zones.
- Retrieve information about the current time zone.
-
Duration Handling:
- Calculate duration in milliseconds, seconds, minutes, hours, days, months, and years.
-
Weekday and Weekend Check:
- Determine the day of the week.
- Check if a date falls on a weekend.
-
Leap Year Check:
- Verify if a year is a leap year.
-
Timestamp Generation:
- Retrieve timestamps, Unix timestamps, and other time-related components.
-
Relative Time:
- Express time differentials with the
fromNow
function.
- Express time differentials with the
-
Calendar Functions:
- Access information like day of the year, week of the year, days in a month, days in a year, quarter, and weeks in a month.
-
Validation:
- Ensure date validity.
- Perform checks like before, after, equal, today, tomorrow, and yesterday.
// ts
import WorldDate from 'world-date';
const currentDate = new WorldDate();
const parsedDate = WorldDate.setLocaleDateTimes(20, 3, 2026, 8, 30);
console.log(currentDate.toISOString());
console.log(currentDate.toUTCString());
console.log(currentDate.toLocaleString());
console.log(parsedDate.toISOString());
console.log(parsedDate.toUTCString());
console.log(parsedDate.toLocaleString());
npm install world-date
This TypeScript constructor function initializes a Date object with the current date or a provided date.
date
(optional): Thedate
parameter in the constructor is an optional parameter of typeDate
. If aDate
object is provided when creating an instance of the class, it will be used to initialize thedate
property of the class. If noDate
object is provided, the current date.
import WorldDate from 'world-date';
const currentDate = new WorldDate();
console.log(currentDate.toLocaleString());
The function addMilliseconds
adds a specified number of milliseconds to a date object and returns a new WorldDate
object.
milliseconds
: Themilliseconds
parameter represents the number of milliseconds to add to the current date and time.
A new WorldDate
object is being returned, which is created using the result
Date object.
const newDate = new WorldDate().addMilliseconds(1000);
console.log(newDate);
The function minusMinutes
subtracts a specified number of minutes from a date and returns a new WorldDate
object.
minutes
: TheminusMinutes
function takes a parameterminutes
of type number, which represents the number of minutes to subtract from the current date and time. If theminutes
value is negative, an error is thrown indicating that minutes cannot be negative. The function then calculates the new date and time.
A new WorldDate
object is being returned, which is created using the modified Date
object after subtracting the specified number of minutes.
// Usage
const newDate = new WorldDate().minusMinutes(1000);
console.log(newDate);
The function addMinutes
adds a specified number of minutes to a date and returns a new WorldDate
object.
minutes
: TheaddMinutes
function takes a parameterminutes
of typenumber
, which represents the number of minutes to add to the current date and time. If theminutes
value is negative, an error is thrown indicating that minutes cannot be negative.
A new WorldDate
object is being returned, which is created using the updated date after adding the specified number of minutes.
const newDate = new WorldDate().addMinutes(30);
console.log(newDate);
The function minusMinutes
subtracts a specified number of minutes from a date and returns a new WorldDate
object.
minutes
: TheminusMinutes
function takes a parameterminutes
of type number, which represents the number of minutes to subtract from the current date and time. If theminutes
value is negative, an error is thrown indicating that minutes cannot be negative.
A new WorldDate
object is being returned, which is created using the modified Date
object after subtracting the specified number of minutes.
const newDate = new WorldDate().minusMinutes(30);
console.log(newDate); // Assuming WorldDate class is used
The function addHours
adds a specified number of hours to a date and returns a new WorldDate
object.
hours
: Thehours
parameter is a number that represents the number of hours to add to the current date and time.
A new instance of the WorldDate
class is being returned, which is created using the modified Date
object result
.
const newDate = new WorldDate().addHours(3);
console.log(newDate); // Assuming WorldDate class is used
The minusHours
function subtracts a specified number of hours from a WorldDate
object.
hours
: Thehours
parameter in theminusHours
function represents the number of hours that you want to subtract from the current date and time.
A new instance of the WorldDate
class is being returned, which is created using the modified Date
object result
.
const newDate = new WorldDate().minusHours(2);
console.log(newDate);
The function addDays
takes a number of days as input and returns a new WorldDate
object with the specified number of days added to the original date.
days
: Thedays
parameter in theaddDays
function represents the number of days to add to the current date. This function takes a number as input, which should be a positive integer representing the number of days to add. If thedays
parameter is negative, an error is thrown.
The addDays
function returns a new WorldDate
object that represents the date after adding the specified number of days to the original date.
const newDate = new WorldDate().addDays(7);
console.log(newDate);
The minusDays
function subtracts a specified number of days from a date and returns a new date object.
days
: Thedays
parameter in theminusDays
function represents the number of days to subtract from the current date. This function is designed to calculate a new date by subtracting the specified number of days from the current date.
A new WorldDate
object is being returned, which is created using the result of subtracting the specified number of days from the original date.
const newDate = new WorldDate().minusDays(3);
console.log(newDate);
The function addMonths
adds a specified number of months to a date and returns a new WorldDate
object.
months
: Themonths
parameter in theaddMonths
function represents the number of months to add to the current date. It is a number value that specifies the increment or decrement in months.
A new WorldDate
object is being returned, which is created using the modified date after adding the specified number of months.
const newDate = new WorldDate().addMonths(6);
console.log(newDate);
The minusMonths
function in TypeScript subtracts a specified number of months from a date and returns a new WorldDate
object.
months
: Themonths
parameter in theminusMonths
function represents the number of months to subtract from the current date.
A new WorldDate
object is being returned with the date value updated by subtracting the specified number of months.
const newDate = new WorldDate().minusMonths(3);
console.log(newDate);
The function addYears
adds a specified number of years to a date and returns a new WorldDate
object.
years
: Theyears
parameter is a number that represents the number of years to add to the current date in theWorldDate
object.
A new WorldDate
object with the date increased by the specified number of years.
const newDate = new WorldDate().addYears(5);
console.log(newDate);
The minusYears
function subtracts a specified number of years from a given date and returns a new WorldDate
object.
years
: Theyears
parameter in theminusYears
function represents the number of years that you want to subtract from the current year of a given date.
A new WorldDate
object with the date value decreased by the specified number of years.
const newDate = new WorldDate().minusYears(2);
console.log(newDate);
The function diffInMilliseconds
calculates the difference in milliseconds between the date of the WorldDate
object passed as a parameter and the date of the current object.
date
: Thedate
parameter in thediffInMilliseconds
function is of typeWorldDate
, which likely represents a date object specific to your application or system. The function calculates the difference in milliseconds between thedate
passed as an argument and thethis.date
property of the object.
The function diffInMilliseconds
is returning the difference in milliseconds between the date
passed as a parameter and the date
property of the current object (this
).
const date1 = new WorldDate();
const date2 = new WorldDate();
const difference = date1.diffInMilliseconds(date2);
console.log(difference);
The function diffInSeconds
calculates the difference in seconds between the current date and a given WorldDate
.
date
: Thedate
parameter in thediffInSeconds
function is of typeWorldDate
, which represents a date and time in the world.
The function diffInSeconds
returns the difference in seconds between the current date and the provided WorldDate
object. It calculates this difference by first converting the milliseconds difference to seconds using Math.floor(this.diffInMilliseconds(date) / 1000)
.
const date1 = new WorldDate();
const date2 = new WorldDate();
const difference = date1.diffInSeconds(date2);
console.log(difference);
The function diffInMinutes
calculates the difference in minutes between the current date and a given WorldDate
.
date
: Thedate
parameter in thediffInMinutes
function is of typeWorldDate
, which represents a date and time in the world. This parameter is used to calculate the difference in minutes between the current date and the providedWorldDate
date.
The function diffInMinutes
returns the difference in minutes between the current date and the provided WorldDate
parameter. It calculates this difference by first getting the difference in seconds using the diffInSeconds
method and then converting that to minutes by dividing by 60 and flooring the result.
const date1 = new WorldDate();
const date2 = new WorldDate().addMinutes(30);
const difference = date1.diffInMinutes(date2);
console.log(difference);
The function diffInHours
calculates the difference in hours between the current date and a given WorldDate
.
date
: Thedate
parameter in thediffInHours
function is of typeWorldDate
, which represents a date and time in the world. The function calculates the difference in hours between the current date and the providedWorldDate
object.
The function diffInHours
returns the difference in hours between the current date and the provided WorldDate
object by first calculating the difference in minutes and then dividing it by 60 to get the hours.
const date1 = new WorldDate();
const date2 = new WorldDate().addHours(3);
const difference = date1.diffInHours(date2);
console.log(difference);
The function diffInDays
calculates the difference in days between the current date and a given date.
date
: Thedate
parameter in thediffInDays
function represents aWorldDate
object, which likely contains information about a specific date and time in the world. This function calculates the difference in days between the current date and the date provided as an argument.
The function diffInDays
returns the difference in days between the current date and the provided WorldDate
parameter. It calculates this difference by first finding the difference in hours using the diffInHours
method and then dividing that by 24 to convert it to days. The result is then rounded down using Math.floor
before being returned.
const date1 = new WorldDate();
const date2 = new WorldDate().addDays(5);
const difference = date1.diffInDays(date2);
console.log(difference);
The function diffInMonths
calculates the difference in months between two WorldDate objects.
date
: Thedate
parameter in thediffInMonths
function is an object of typeWorldDate
. It seems like the function is calculating the difference in months between thedate
property of the current object (this.date
) and thedate
property of the passedWorldDate
.
The function diffInMonths(date: WorldDate): number
returns the difference in months between the date stored in the current object (this.date
) and the date passed as an argument (date
).
const date1 = new WorldDate();
const date2 = new WorldDate().addMonths(6);
const difference = date1.diffInMonths(date2);
console.log(difference);
The function calculates the difference in years between the current date and a given date.
date
: Thedate
parameter in thediffInYears
function is of typeWorldDate
, which likely represents a date object in the context of your program. The function calculates the difference in years between the year of the current date (this.date
) and the year of the providedWorldDate
.
The function diffInYears
returns the difference in years between the year of the current date (this.date
) and the year of the input WorldDate
object (date.date
).
const date1 = new WorldDate();
const date2 = new WorldDate().addYears(2);
const difference = date1.diffInYears(date2);
console.log(difference);
The isBefore
function in TypeScript compares the time of the current date with another date to determine if it is before that date.
date
: Thedate
parameter in theisBefore
function is of typeWorldDate
, which seems to be a custom date object. The function compares the time of the current date object (this.date
) with the time of thedate
parameter to determine if the current date is before the.
A boolean value indicating whether the date stored in the current object is before the date passed as a parameter.
const date1 = new WorldDate();
const date2 = new WorldDate().addDays(5);
const isBeforeDate = date1.isBefore(date2);
console.log(isBeforeDate);
The function isAfter
compares the date of the current object with the date of another object and returns true if the current date is after the other date.
date
: Thedate
parameter in theisAfter
function is of typeWorldDate
, which seems to be a custom date object. The function compares the time of the current date object (this.date
) with the time of thedate
parameter to determine if the current date is after the.
A boolean value indicating whether the date stored in the current object is after the date passed as a parameter.
const date1 = new WorldDate();
const date2 = new WorldDate().addDays(5);
const isAfterDate = date1.isAfter(date2);
console.log(isAfterDate);
The isEqual
function in TypeScript compares the time values of two WorldDate
objects and returns a boolean indicating whether they are equal.
date
: Thedate
parameter in theisEqual
function is of typeWorldDate
, which represents a date object in the world. The function compares the time value of the current date object (this.date
) with the time value of thedate
parameter to determine if they are equal.
A boolean value indicating whether the time of the date stored in the current object is equal to the time of the date passed as a parameter.
const date1 = new WorldDate();
const date2 = new WorldDate();
const isEqualDate = date1.isEqual(date2);
console.log(isEqualDate);
The isSameDay
function in TypeScript checks if two WorldDate objects represent the same day.
date
: TheisSameDay
function compares the year, month, and date components of two dates to determine if they represent the same day. The function takes aWorldDate
object nameddate
as a parameter for comparison. TheWorldDate
object likely contains information about a specific date.
A boolean value indicating whether the year, month, and date of the current date object (this.date
) are the same as the year, month, and date of the WorldDate
object passed as a parameter (date
).
const date1 = new WorldDate();
const date2 = new WorldDate();
const isSameDay = date1.isSameDay(date2);
console.log(isSameDay);
The function isSameMonth
compares the year and month of two WorldDate objects to determine if they are in the same month.
date
: TheisSameMonth
function is checking if the year and month of the current date (this.date
) are the same as the year and month of the inputWorldDate
object (date.date
). If both the year and month match, the function returnstrue
, indicating that the two.
The function isSameMonth
returns a boolean value, which indicates whether the year and month of the current date object (this.date
) are the same as the year and month of the date object passed as a parameter (date.date
).
const date1 = new WorldDate();
const date2 = new WorldDate();
const isSameMonth = date1.isSameMonth(date2);
console.log(isSameMonth);
The function isSameYear
compares the year of the current date with the year of a given WorldDate
object and returns a boolean indicating whether they are the same.
date
: Thedate
parameter in theisSameYear
function is of typeWorldDate
, which contains a propertydate
that represents a date object. The function compares the year of the current date with the year of the providedWorldDate
object to determine if they are the same.
A boolean value indicating whether the year of the current date object (this.date
) is the same as the year of the input WorldDate
object (date.date
).
const date1 = new WorldDate();
const date2 = new WorldDate();
const isSameYear = date1.isSameYear(date2);
console.log(isSameYear);
The startOfDay
function in TypeScript creates a new WorldDate
object with the time set to midnight (00:00:00.000) in UTC.
A new WorldDate
object with the time set to the start of the day (00:00:00.000) in UTC time zone.
const startOfToday = new WorldDate().startOfDay();
console.log(startOfToday);
The endOfDay
function in TypeScript creates a new WorldDate
object with the time set to 23:59:59.999.
An instance of the WorldDate
class with the time set to the end of the day (23:59:59.999) based on the current date.
const endOfToday = new WorldDate().endOfDay();
console.log(endOfToday);
The startOfMonth
function in TypeScript creates a new WorldDate
object set to the first day of the current month with the time set to midnight.
An instance of WorldDate
representing the first day of the month for the given date.
const startOfMonthDate = new WorldDate().startOfMonth();
console.log(startOfMonthDate);
The endOfMonth
function in TypeScript returns the last moment of the current month based on the input date.
A WorldDate
object representing the last millisecond of the current month.
const endOfMonthDate = new WorldDate().endOfMonth();
console.log(endOfMonthDate);
The startOfYear
function in TypeScript creates a new WorldDate
object representing the start of the year based on the current date.
An instance of the WorldDate
class representing the first day of the year based on the date stored in the current object.
const startOfYearDate = new WorldDate().startOfYear();
console.log(startOfYearDate);
The endOfYear
function in TypeScript returns a WorldDate
object representing the last moment of the current year.
A WorldDate
object representing the last moment of the year of the original date.
const endOfYearDate = new WorldDate().endOfYear();
console.log(endOfYearDate);
The static now()
function returns a new instance of the WorldDate
class.
An instance of the WorldDate
class is being returned.
const currentDate = WorldDate.now();
console.log(currentDate);
The function tomorrow
returns a WorldDate
object representing the start of the next day.
A new WorldDate
object representing tomorrow's date at the start of the day.
const tomorrowDate = WorldDate.tomorrow();
console.log(tomorrowDate);
The yesterday
function in TypeScript returns a WorldDate
object representing the start of the previous day.
An instance of the WorldDate
class representing the date of yesterday.
const yesterdayDate = WorldDate.yesterday();
console.log(yesterdayDate);
The function fromISOString
creates a new WorldDate
object from a given ISO date string.
dateString
: ThedateString
parameter is a string that represents a date in ISO format, such as "2022-01-01T12:00:00Z". ThefromISOString
function attempts to create a newWorldDate
object by parsing this string into a JavaScriptDate
.
A WorldDate
object is being returned.
const dateString = "2022-01-01T12:00:00Z";
const worldDate = WorldDate.fromISOString(dateString);
console.log(worldDate);
The function fromUTCString
converts a UTC date string into a WorldDate
object.
dateString
: ThedateString
parameter is a string representing a date and time in UTC format. It is used as input to create a newWorldDate
object by converting the string to a JavaScriptDate
object.
An instance of the WorldDate
class is being returned, created from a Date
object parsed from the input dateString
.
const dateString = "2022-01-01T12:00:00Z";
const worldDate = WorldDate.fromUTCString(dateString);
console.log(worldDate);
The function setLocaleDateTimes
in TypeScript sets a custom date and time in a WorldDate
object.
day
: Theday
parameter represents the day of the month.month
: Themonth
parameter in thesetLocaleDateTimes
function represents the month of the year. It is a number between 1 and 12, where 1 represents January and 12 represents December.year
: Theyear
parameter is the year value for the date you want to set.hours
(optional): Thehours
parameter in thesetLocaleDateTimes
function represents the hour value in a 24-hour format (0-23). It is an optional parameter that allows you to specify the hour component of the date and time you want to set. If provided, it sets the hours component.minutes
(optional): Theminutes
parameter in thesetLocaleDateTimes
function represents the minutes component of the time to be set. It is an optional parameter, meaning it can be provided but is not required. If a value is not provided forminutes
, it defaults to 0.seconds
(optional): Theseconds
parameter in thesetLocaleDateTimes
function is an optional parameter that represents the seconds component of the time. If a value is provided for theseconds
parameter, it will be used to set the seconds component of the date and time. If no value is provided, it defaults to 0.milliseconds
(optional): Themilliseconds
parameter in thesetLocaleDateTimes
function is an optional parameter that represents the milliseconds value of the time to be set. If provided, it will set the milliseconds of the date object being created or modified. If not provided, it defaults to 0.
An instance of the WorldDate
class is being returned, which is created using the parsed date values provided as parameters to the setLocaleDateTimes
function.
const customDate = WorldDate.setLocaleDateTimes(15, 3, 2024, 14, 30, 0, 0);
console.log(customDate.toLocaleString());
This function returns the milliseconds component of the date in UTC time.
The getUTCMilliseconds()
method returns the milliseconds (from 0 to 999) of the specified date and time in Coordinated Universal Time (UTC).
const currentDate = new WorldDate();
const milliseconds = currentDate.getUTCMilliseconds();
console.log(milliseconds);
The getUTCSeconds
function returns the seconds component of a Date object in Coordinated Universal Time (UTC).
The getUTCSeconds()
method is being called on the date
property of the current object, and it returns the seconds (from 0 to 59) of the specified date and time in Coordinated Universal Time (UTC).
const currentDate = new WorldDate();
const seconds = currentDate.getUTCSeconds();
console.log(seconds);
This function returns the minutes component of the UTC time from a given date.
The getUTCMinutes()
method is being called on the date
property of the current object, and it returns the minutes (from 0 to 59) of the UTC time of the date stored in the date
property.
const currentDate = new WorldDate();
const minutes = currentDate.getUTCMinutes();
console.log(minutes);
This function returns the hour component of a Date object in Coordinated Universal Time (UTC).
The getUTCHours()
method is being called on the date
object, which returns the hour (0-23) in Coordinated Universal Time (UTC).
const currentDate = new WorldDate();
const hours = currentDate.getUTCHours();
console.log(hours);
The function getUTCDay
returns the day of the week (0-6) for a given date in UTC time.
The getUTCDay()
method returns the day of the week (from 0 to 6) for the specified date according to universal time (UTC).
const currentDate = new WorldDate();
const dayOfWeek = currentDate.getUTCDay();
console.log(dayOfWeek);
The getUTCDate
function returns the day of the month (1-31) of a Date object in UTC time.
The getUTCDate()
method is returning the day of the month (from 1 to 31) of the date object in Coordinated Universal Time (UTC).
const currentDate = new WorldDate();
const dayOfMonth = currentDate.getUTCDate();
console.log(dayOfMonth);
This function returns the month component (0-11) of a Date object in UTC time.
The getUTCMonth()
method is being called on the date
object to retrieve the month component of the date in UTC time. The method returns a number representing the month, where January is 0 and December is 11.
const currentDate = new WorldDate();
const month = currentDate.getUTCMonth();
console.log(month);
The function getUTCYear()
returns the UTC year of a given date.
The getUTCYear()
method returns the year (as a four-digit number) of the specified date according to universal time.
const currentDate = new WorldDate();
const year = currentDate.getUTCYear();
console.log(year);
The getTime function returns the time in milliseconds of a given date.
The getTime()
method is being called on the date
property of the current object, and it returns the number of milliseconds since January 1, 1970, 00:00:00 UTC represented by the Date
object.
const currentDate = new WorldDate();
const timeInMilliseconds = currentDate.getTime();
console.log(timeInMilliseconds);
The getTimestamp
function in TypeScript returns the timestamp of a date object.
The getTimestamp
method is returning the timestamp value of the date
property in milliseconds.
const currentDate = new WorldDate();
const timestamp = currentDate.getTimestamp();
console.log(timestamp);
The getUnixTimestamp
function returns the Unix timestamp of a given date.
The getUnixTimestamp
method is returning the Unix timestamp of the current date and time in seconds.
const currentDate = new WorldDate();
const unixTimestamp = currentDate.getUnixTimestamp();
console.log(unixTimestamp);
The getDayOfYear
function calculates the day of the year for a given date.
The getDayOfYear
method is returning the day of the year for the given date. It calculates the day of the year by finding the difference in milliseconds between the given date and the start of the year, then dividing that by the number of milliseconds in a day and rounding down to the nearest whole number.
const currentDate = new WorldDate();
const dayOfYear = currentDate.getDayOfYear();
console.log(dayOfYear);
The function getWeekOfYear
calculates the week number of a given date within a year.
The getWeekOfYear
function returns the week number of the year for a given date.
const currentDate = new WorldDate();
const weekOfYear = currentDate.getWeekOfYear();
console.log(weekOfYear);
This TypeScript function returns the number of days in the month of a given date.
The getDaysInMonth()
function returns the number of days in the current month of the date object it is called on.
const currentDate = new WorldDate();
const daysInMonth = currentDate.getDaysInMonth();
console.log(daysInMonth);
The function getDaysInYear
returns the number of days in a year based on whether it is a leap year or not.
The getDaysInYear()
method returns the number of days in a year based on whether it is a leap year or not. If the year of the date object is divisible by 4 (leap year condition), it returns 366 (number of days in a leap year), otherwise it returns 365 (number of days in a non-leap year).
const currentDate = new WorldDate();
const daysInYear = currentDate.getDaysInYear();
console.log(daysInYear);
The function getQuarter()
returns the quarter of the year based on the month of a given date.
The getQuarter()
function returns the current quarter of the year based on the month of the date.
const currentDate = new WorldDate();
const quarter = currentDate.getQuarter();
console.log(quarter);
The function getWeeksInMonth
calculates the number of weeks in a month based on the number of days in that month.
The function getWeeksInMonth()
returns the number of weeks in a month based on the number of days in that month. It calculates this by dividing the total number of days in the month by 7 (the number of days in a week) and then flooring the result to get the whole number of weeks.
const currentDate = new WorldDate();
const weeksInMonth = currentDate.getWeeksInMonth();
console.log(weeksInMonth);
The function getZone()
returns the time zone offset in hours for the current date.
The getZone()
method returns the time zone offset in hours for the current date. It calculates the time zone offset by dividing the time zone offset in minutes by 60 and returning the result.
const date = new WorldDate();
console.log(date.getZone());
The function getOffset()
returns the time zone offset in minutes for the current date.
The getOffset()
method returns the time zone offset in minutes for the current date.
const date = new WorldDate();
console.log(date.getOffset());
The function getLocalDay()
returns the day of the week (0-6) for the current date according to local time.
The getLocalDay()
method returns the day of the week (from 0 to 6) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalDay());
The function getLocalDate()
returns the day of the month (1-31) for the current date according to local time.
The getLocalDate()
method returns the day of the month (from 1 to 31) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalDate());
The function getLocalMonth()
returns the month (0-11) for the current date according to local time.
The getLocalMonth()
method returns the month (from 0 to 11) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalMonth()); // 11
The function getLocalYear()
returns the year for the current date according to local time.
The getLocalYear()
method returns the year for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalYear());
The function getLocalHours()
returns the hour (0-23) for the current date according to local time.
The getLocalHours()
method returns the hour (from 0 to 23) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalHours());
The function getLocalMinutes()
returns the minutes (0-59) for the current date according to local time.
The getLocalMinutes()
method returns the minutes (from 0 to 59) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalMinutes());
The function getLocalSeconds()
returns the seconds (0-59) for the current date according to local time.
The getLocalSeconds()
method returns the seconds (from 0 to 59) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalSeconds());
The function getLocalMilliseconds()
returns the milliseconds (0-999) for the current date according to local time.
The getLocalMilliseconds()
method returns the milliseconds (from 0 to 999) for the current date according to local time.
const date = new WorldDate();
console.log(date.getLocalMilliseconds()); // 500
The function fromNow()
returns a string representing the relative time from the current date to the stored date.
The fromNow()
method returns a string representing the relative time from the current date to the date stored in the date
property. It calculates the difference in milliseconds between the current date and the stored date and then formats the result as a human-readable string.
const date = new WorldDate();
console.log(date.fromNow()); // just now
The function setUTCMilliseconds
sets the milliseconds component of the date in UTC time.
milliseconds
(number): A number representing the milliseconds component of the date in Coordinated Universal Time (UTC).
The setUTCMilliseconds
method returns a new WorldDate
object with the milliseconds component set to the specified value.
const date = new WorldDate();
const newDate = date.setUTCMilliseconds(500);
console.log(date);
The function setUTCSeconds
sets the seconds component of the date in UTC time.
seconds
(number): A number representing the seconds component of the date in Coordinated Universal Time (UTC).
The setUTCSeconds
method returns a new WorldDate
object with the seconds component set to the specified value.
const date = new WorldDate();
const newDate = date.setUTCSeconds(30);
console.log(newDate);
The function setUTCMinutes
sets the minutes component of the date in UTC time.
minutes
(number): A number representing the minutes component of the date in Coordinated Universal Time (UTC).
The setUTCMinutes
method returns a new WorldDate
object with the minutes component set to the specified value.
const date = new WorldDate();
const newDate = date.setUTCMinutes(45);
console.log(newDate);
The function setUTCHours
sets the hour component of the date in UTC time.
hours
(number): A number representing the hour component of the date in Coordinated Universal Time (UTC).
The setUTCHours
method returns a new WorldDate
object with the hour component set to the specified value.
const date = new WorldDate();
const newDate = date.setUTCHours(12);
console.log(newDate);
The function setUTCDate
sets the day of the month (1-31) of the date in UTC time.
date
(number): A number representing the day of the month (from 1 to 31) in Coordinated Universal Time (UTC).
The setUTCDate
method returns a new WorldDate
object with the day of the month set to the specified value.
const date = new WorldDate();
const newDate = date.setUTCDate(15);
console.log(newDate);
The function setUTCMonth
sets the month (1-12) of the date in UTC time.
month
(number): A number representing the month of the year (from 1 to 12) in Coordinated Universal Time (UTC).
The setUTCMonth
method returns a new WorldDate
object with the month set to the specified value.
const date = new WorldDate();
const newDate = date.setUTCMonth(12);
console.log(newDate);
The function setUTCYear
sets the year of the date in UTC time.
year
(number): A number representing the year of the date in Coordinated Universal Time (UTC).
The setUTCYear
method returns a new WorldDate
object with the year set to the specified value.
const date = new WorldDate();
console.log(date.setUTCYear(2023));
The function setTime
sets the time of the date in UTC time.
time
(number): A number representing the number of milliseconds since January 1, 1970, 00:00:00 UTC.
The setTime
method returns a new WorldDate
object with the time set to the specified value.
const date = new WorldDate();
console.log(date.setTime(1639569045500));
The function setUnixTimestamp
sets the date and time based on a Unix timestamp.
timestamp
(number): A number representing the number of seconds since January 1, 1970, 00:00:00 UTC.
The setUnixTimestamp
method returns a new WorldDate
object with the date and time set to the specified Unix timestamp.
const date = new WorldDate();
console.log(date.setUnixTimestamp(1639569045)); // Output: 2022-12-15T15:30:45.000Z
The setLocalMilliseconds
function sets the milliseconds component of the date in local time.
milliseconds
(number): A number representing the milliseconds component of the date in local time.
The setLocalMilliseconds
method returns a new WorldDate
object with the milliseconds component set to the specified value.
const date = new WorldDate();
console.log(date.setLocalMilliseconds(500));
The setLocalSeconds
function sets the seconds component of the date in local time.
seconds
(number): A number representing the seconds component of the date in local time.
The setLocalSeconds
method returns a new WorldDate
object with the seconds component set to the specified value.
const date = new WorldDate();
console.log(date.setLocalSeconds(45));
The setLocalMinutes
function sets the minutes component of the date in local time.
minutes
(number): A number representing the minutes component of the date in local time.
The setLocalMinutes
method returns a new WorldDate
object with the minutes component set to the specified value.
const date = new WorldDate();
console.log(date.setLocalMinutes(30));
The setLocalHours
function sets the hour component of the date in local time.
hours
(number): A number representing the hour component of the date in local time.
The setLocalHours
method returns a new WorldDate
object with the hour component set to the specified value.
const date = new WorldDate();
console.log(date.setLocalHours(15));
The setLocalDate
function sets the day of the month (1-31) of the date in local time.
date
(number): A number representing the day of the month (from 1 to 31) in local time.
The setLocalDate
method returns a new WorldDate
object with the day of the month set to the specified value.
const date = new WorldDate();
console.log(date.setLocalDate(15));
The setLocalMonth
function sets the month (1-12) of the date in local time.
month
(number): A number representing the month of the year (from 1 to 12) in local time.
The setLocalMonth
method returns a new WorldDate
object with the month set to the specified value.
const date = new WorldDate();
console.log(date.setLocalMonth(12));
The setLocalYear
function sets the year of the date in local time.
year
(number): A number representing the year of the date in local time.
The setLocalYear
method returns a new WorldDate
object with the year set to the specified value.
const date = new WorldDate();
console.log(date.setLocalYear(2023));
The isValid
function checks if the date is valid.
The isValid
method returns a boolean value indicating whether the date is valid.
const date = new WorldDate();
console.log(date.isValid());
The isLeapYear
function checks if the year of the date is a leap year.
The isLeapYear
method returns a boolean value indicating whether the year of the date is a leap year.
const date = new WorldDate();
console.log(date.isLeapYear());
The isWeekend
function checks if the day of the date is a weekend.
The isWeekend
method returns a boolean value indicating whether the day of the date is a weekend.
const date = new WorldDate();
console.log(date.isWeekend());
The isToday
function checks if the date is today.
The isToday
method returns a boolean value indicating whether the date is today.
const date = new WorldDate();
console.log(date.isToday());
The isTomorrow
function checks if the date is tomorrow.
The isTomorrow
method returns a boolean value indicating whether the date is tomorrow.
const date = new WorldDate();
console.log(date.isTomorrow()); // Output: false
The isYesterday
function checks if the date is yesterday.
The isYesterday
method returns a boolean value indicating whether the date is yesterday.
const date = new WorldDate();
console.log(date.isYesterday()); // Output: false
The toTimeZone
function converts the date and time to a different time zone.
zone
: A number representing the time zone offset in hours.
The toTimeZone
method returns a new WorldDate
object with the date and time converted to the specified time zone.
const date = new WorldDate();
const newData = date.toTimeZone(-5);
console.log(newData.toLocaleString());
The toTimestamp
function returns the timestamp of the date.
The toTimestamp
method returns the timestamp value of the date in milliseconds.
const date = new WorldDate();
console.log(date.toTimestamp());
The toUnix
function returns the Unix timestamp of the date.
The toUnix
method returns the Unix timestamp of the date in seconds.
const date = new WorldDate();
console.log(date.toUnix());
The toString
function returns a string representing the date and time.
The toString
method returns a string representing the date and time.
const date = new WorldDate();
console.log(date.toString()); // "Wed Mar 15 2024 12:00:00 GMT+0000 (Coordinated Universal Time)"
The toDateString
function returns a string representing the date.
The toDateString
method returns a string representing the date.
const date = new WorldDate();
console.log(date.toDateString()); // "Wed Mar 15 2024"
The toTimeString
function returns a string representing the time.
The toTimeString
method returns a string representing the time.
const date = new WorldDate();
console.log(date.toTimeString()); // "12:00:00 GMT+0000 (Coordinated Universal Time)"
The toLocaleDateString
function returns a string representing the date in the current locale.
The toLocaleDateString
method returns a string representing the date in the current locale.
const date = new WorldDate();
console.log(date.toLocaleDateString()); // "3/15/2024"
The toLocaleTimeString
function returns a string representing the time in the current locale.
The toLocaleTimeString
method returns a string representing the time in the current locale.
const date = new WorldDate();
console.log(date.toLocaleTimeString()); // "12:00:00 AM"
The toLocaleString
function returns a string representing the date and time in the current locale.
The toLocaleString
method returns a string representing the date and time in the current locale.
const date = new WorldDate();
console.log(date.toLocaleString()); // "3/15/2024, 12:00:00 AM"
The toLocaleFormat
function returns a string representing the date and time in the current locale.
options
: An object with properties that control the format of the string.
The toLocaleFormat
method returns a string representing the date and time in the current locale.
const date = new WorldDate();
console.log(date.toLocaleFormat({ weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })); // "Wednesday, December 15, 2022"
The toISOString
function returns a string representing the date and time in ISO format.
The toISOString
method returns a string representing the date and time in ISO format.
const date = new WorldDate();
console.log(date.toISOString());
The toUTCString
function returns a string representing the date and time in Coordinated Universal Time (UTC).
The toUTCString
method returns a string representing the date and time in Coordinated Universal Time (UTC).
const date = new WorldDate();
console.log(date.toUTCString());
The getCalendar
function returns a calendar layout for the month of the date.
The getCalendar
method returns a two-dimensional array representing the calendar layout for the month of the date. Each element in the array represents a week, and each subarray represents the days of the week.
const date = new WorldDate();
console.log(date.getCalendar());
The getCalendarFrom
function returns a calendar layout for the month of the date.
month
: A number representing the month of the year (from 0 to 11) to start the calendar layout.year
: A number representing the year to start the calendar layout.
The getCalendarFrom
method returns a two-dimensional array representing the calendar layout for the month of the date. Each element in the array represents a week, and each subarray represents the days of the week.
const date = new WorldDate();
console.log(date.getCalendarFrom(0, 11, 2022));
The isDST
function checks if the date is in daylight saving time.
The isDST
method returns a boolean value indicating whether the date is in daylight saving time.
const date = new WorldDate();
console.log(date.isDST()); // false
The getDaylightSavingTime
function returns the number of milliseconds in daylight saving time for the date.
The getDaylightSavingTime
method returns the number of milliseconds in daylight saving time for the date.
const date = new WorldDate();
console.log(date.getDaylightSavingTime()); // 3600000