Returns the date and time in the specified time zone or in the current one if the time zone is not specified (by default, the company’s time zone). Example:
const date = new TDate(2021, 1, 20);
const time = new TTime(3, 15, 0, 0);
const datetime = date.asDatetime(time);
The default format is YYYY-MM-DD. Use the following options to format dates:
YYYY, y is for the year.
MM is for the month with a leading zero.
M is for the month without a leading zero.
DD is for the day with a leading zero.
D is for the day without a leading zero.
d is for the day of the week.
Example:
const date = new TDate(2021, 1, 20);
const formatDate = date.format();
Date
Constructors:
new TDate(): TDate; new TDate(year: number, month: number, day: number): TDate;alues of this type are immutable, so mutation methods return an updated value without modifying the original.
const date = new TDate(2022, 2, 24); // 2022-02-24 const newDate = date.addDate(0, 1, 5); // 2022-03-29Note that the type TDate оdiffers from the built-in JavaScript type
Date. This type contains only date information, without the time of day.Hierarchy
Properties
Readonly day
Day.
Example:
const date = new TDate(2021, 1, 20); const day = date.day;Readonly month
Month.
Example:
const date = new TDate(2021, 1, 20); const month = date.month;Readonly year
Year.
Example:
const date = new TDate(2021, 1, 20); const year = date.year;Methods
addDate
Add a date.
Example:
const date = new TDate(2021, 1, 20); const newDate = date.addDate(0, 1, 5);Parameters
years: number
month: number
days: number
Returns TDate
after
Checks whether the specified date is later than another.
Example:
const startDate = new TDate(2021, 1, 20); const endDate = new TDate(2021, 1, 21); const after = startDate.after(endDate); // falseParameters
date: TDatetime | TDate
Returns boolean
afterOrEqual
Checks whether the current date is the same as or later than
date.Example:
const startDate = new TDate(2021, 1, 20); const endDate = new TDate(2021, 1, 21); const equal = startDate. afterOrEqual(endDate); // falseParameters
date: TDatetime | TDate
Returns boolean
asDatetime
Conversion to date and time.
Returns the date and time in the specified time zone or in the current one if the time zone is not specified (by default, the company’s time zone).
Example:
const date = new TDate(2021, 1, 20); const time = new TTime(3, 15, 0, 0); const datetime = date.asDatetime(time);Parameters
time: TTime
Optional tz: TTimezone
Returns TDatetime
before
Checks whether the specified date is earlier than another.
Example:
const startDate = new TDate(2021, 1, 20); const endDate = new TDate(2021, 1, 21); const before = startDate.before(endDate); // trueParameters
date: TDatetime | TDate
Returns boolean
beforeOrEqual
Checks whether the current date is the same as or earlier than
date.Example:
const startDate = new TDate(2021, 1, 20); const endDate = new TDate(2021, 1, 21); const equal = startDate. beforeOrEqual(endDate); // trueParameters
date: TDatetime | TDate
Returns boolean
equal
Checks whether two date objects have the same value.
Example:
const startDate = new TDate(2021, 1, 20); const endDate = new TDate(2021, 1, 21); const equal = startDate.equal(endDate); // falseParameters
date: TDatetime | TDate
Returns boolean
format
Converts the date to the required format.
The default format is
YYYY-MM-DD. Use the following options to format dates:YYYY,yis for the year.MMis for the month with a leading zero.Mis for the month without a leading zero.DDis for the day with a leading zero.Dis for the day without a leading zero.dis for the day of the week. Example:const date = new TDate(2021, 1, 20); const formatDate = date.format();Parameters
Optional format: undefined | string
Returns string
Feedback sent successfully
Thank you for your input