This class provides methods for performing operations on SimpleDateTime objects, such as instantiating objects, for exampleThe class is used to conduct operations on SimpleDateTime objects, for example, instantiating objects.
You can also use this class to perform calculate, change formats of the date-time operations, such as calculations, formatting or converting between date-time or convert between the formats.
SimpleDateTime(dateTime)
Instantiates Use this constructor to instantiate a new SimpleDateTime object with the current or transferred date/time. Specify the date and time value in the UTC timezone.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | String | N | '' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleDateTime |
---|
linenumbers | true |
---|
|
const nowDateTime = new SimpleDateTime();
//
const registrationDateTime = new SimpleDateTime(record.registration_datetime);
//
const yearStartDateTime = new SimpleDateTime('2019-01-01 00:00:00'); |
setValue(dateTime)
This method sets the date and time of the SimpleDateTime object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | A string in the local time zone and the internal format of yyyy-MM-dd HH:mm:ss. | Y | N |
dateTime | A SimpleDateTime object, | Y | N |
dateTime | A JavaScript Number. It sets the value of the object using the Number value as milliseconds past January 1, 1970, 00:00:00. | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
You can also use the values in relative format for the SimpleDateTime constructor. All formats are available in the Relative Formats article.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleDateTime |
---|
linenumbers | true |
---|
|
const yesterdayDatetime = new SimpleDateTime('yesterday');
ss.info(yesterdayDatetime.getValue());
// Info: 2022-02-28 00:00:00
const tomorrowDatetime |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setValue |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00tomorrow');
startDateTime.setValue('2020-01-01 12ss.info(tomorrowDatetime.getValue());
// Info: 2022-03-02 00:00:00
const yesterdayWorkdayDayStart = new SimpleDateTime('yesterday 06:30');
ss.info(startDateTimeyesterdayWorkdayDayStart.getValue());
// 2020-01-01 12:00:00 |
addSeconds(seconds)
This method adds a specified number of seconds to the current SimpleDateTime object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
seconds | Integer | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addSeconds |
---|
linenumbers | true |
---|
|
const registrationDateTimeInfo: 2022-02-28 06:30:00
const fistDayOfNextMonthStart = new SimpleDateTime('first day of next month 00:00');
ss.info(fistDayOfNextMonthStart.getValue());
// Info: 2022-04-01 00:00:00
const rangeStartDatetime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addSeconds(3600);
`first day of ${monthName}`);
ss.info(registrationDateTimerangeStartDatetime .getValue());
// 2019-01Info: 2022-02-01 0900:12:10 |
addDays(days)
This method adds a specified number of days to the current SimpleDateTime object. The negative value of the parameter will subtract the days.
00:00
const YEAR = 2022;
const MONTH = 2;
const monthDatetime = new SimpleDateTime(`${YEAR}-${String(MONTH).padStart(2, '0')}-02 00:00:00`);
const monthName = monthDatetime.getMonthUTC();
ss.info(monthName);
// Info: February |
addDays(days)
This method is used to change the number of days in the current SimpleDateTime object according to the local date and time. The positive value of the parameter adds days to the object, the negative value diminishes the number of daysThe method determines local date and time equivalent to the value saved by the SimpleDateTime object, then adds or subtracts the days using local date and time values.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
days | integer | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addDays |
---|
linenumbers | true |
---|
|
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addDays(3);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-04 08:12:10 |
addWeeksaddMonths(
weeksmonths)
This method adds a specified is used to change the number of weeks to months in the current SimpleDateTime object according to the local date and time. The negative positive value of the parameter will subtract the weeks.The method determines local date and time equivalent to the value saved by the SimpleDateTime object, then adds or subtracts the weeks using local date and time valuesadds months to the object, the negative value diminishes the number of months.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
weeksmonths | Integer | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addWeeksaddMonths |
---|
linenumbers | true |
---|
|
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addWeeksaddMonths(-1);
ss.info(registrationDateTime.getValue());
//Info: 20192018-12-01-08 08:12:10 |
addMonthsaddSeconds(
monthsseconds)
This method adds a specified is used to change the number of months to seconds in the current SimpleDateTime object . The negative according to the local date and time. The positive value of the parameter will subtract the months.The method determines local date and time equivalent to the value saved by the SimpleDateTime object, then adds or subtracts the months using local date and time valuesadds seconds to the object, the negative value diminishes the number of seconds.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
months
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addMonthsaddSeconds |
---|
linenumbers | true |
---|
|
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addMonthsaddSeconds(-13600);
ss.info(registrationDateTime.getValue());
//Info: 20182019-1201-01 0809:12:10 |
addYearsaddWeeks(
yearsweeks)
This method adds a specified is used to change the number of years to weeks in the current SimpleDateTime object according to the local date and time. The negative positive value of the parameter will subtract the years.The method determines local date and time equivalent to the value saved by the SimpleDateTime object, then adds or subtracts the years using local date and time valuesadds weeks to the object, the negative value diminishes the number of weeks.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
yearsweeks | Integer | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | addYearsaddWeeks |
---|
linenumbers | true |
---|
|
const contractStartDateTimeregistrationDateTime = new SimpleDateTime('2019-01-01 0008:0012:0010');
contractStartDateTimeregistrationDateTime.addYearsaddWeeks(1);
ss.info(contractStartDateTimeregistrationDateTime.getValue());
//Info: 20202019-01-0108 0008:0012:0010 |
afteraddYears(
dateTimeyears)
This method allows to compare the date specified by the ‘dateTime‘ parameter with the current date. The method returns TRUE, if the current date is after the specified; otherwise returns FALSEis used to change the number of years in the current SimpleDateTime object according to the local date and time. The positive value of the parameter adds years to the object, the negative value diminishes the number of years.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTimeyears | SimpleDateTime objectInteger | Y | N |
Return:
BooleanThe method returns TRUE if the current date is later than the date specified by the parameter; otherwise, returns FALSEThis method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | afteraddYears |
---|
linenumbers | true |
---|
|
const startDateTimecontractStartDateTime = new SimpleDateTime('20182019-01-01 0700:5800:3500');
const endDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const isStartLaterThanEnd = startDateTime.after(endDateTime);
ss.info(isStartLaterThanEnd); // false |
beforecontractStartDateTime.addYears(1);
ss.info(contractStartDateTime.getValue());
//Info: 2020-01-01 00:00:00 |
after(dateTime)
This method allows to compare the date specified by the ‘dateTime‘ parameter with the current date.
The method returns TRUE, if the current date is before after the specified; otherwise returns falseFALSE.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | SimpleDateTime object | Y | N |
Return:
Type | Description |
---|
Boolean | The method returns TRUE if the current date is earlier later than the date specified by the parameter; otherwise, returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | beforeafter |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2018-01-01 07:58:35');
const endDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const isStartBeforeEndisStartAfterThanEnd = startDateTime.beforeafter(endDateTime);
ss.info(isStartBeforeEndisStartAfterThanEnd);
//Info: truefalse |
compareTobefore(dateTime)
This method compares two date and time objects to determine whether they are equivalent or notmethod allows to compare the date specified by the ‘dateTime‘ parameter with the current date.
The method returns TRUE, if the current date is before the specified; otherwise returns false.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | SimpleDateTime object | Y | N |
Return:
Type | Description |
---|
0 | Dates are equal |
Boolean | The method returns TRUE if the current date is earlier than | 1 | Object's date is after the date specified | in the parameter.-1 | Object's date is before the date specified in the parameterby the parameter; otherwise, returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | compareTobefore |
---|
linenumbers | true |
---|
|
const firstDateTimestartDateTime = new SimpleDateTime('20192018-01-01 0807:0058:0035');
const secondDateTimeendDateTime = new SimpleDateTime('20182019-01-01 08:00:00');
const thirdDateTimeisStartBeforeEnd = new SimpleDateTime('2018-01-01 08:00:00'startDateTime.before(endDateTime);
ss.info(thirdDateTime.compareTo(secondDateTime )); // 0
ss.info(firstDateTime.compareTo(secondDateTime)); // 1
ss.info(secondDateTime.compareTo(firstDateTime)); // -1 |
equals(isStartBeforeEnd);
//Info: true |
compareTo(dateTime)
This method compares a datetime with an existing value if they are equal.two date and time objects to determine whether they are equal and, if not, the method defines which goes after or before the other.
Parameter(s)Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | SimpleDateTime object. | Y | N |
Return:
Type | Description | Boolean | |
---|
0 | Dates are equal. |
1 | Object's date is after the date specified in the parameter. |
-1 | Object's date is before the date specified in the parameter | This method returns TRUE if the date are equal; otherwise, it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | equalscompareTo |
---|
linenumbers | true |
---|
|
const firstDateTimebegin = new SimpleDateTime('2019-0104-01 08:0015:00');
const secondDateTimeend = new SimpleDateTime('20182019-0105-01 0801:00:00');
const thirdDateTime = new SimpleDateTime('2018-01-01 08:00:00');
ss.info(begin.compareTo(end)); // -1
ss.info(firstDateTimeend.equalscompareTo(secondDateTimebegin)); // false1
ss.info(thirdDateTimebegin.equalscompareTo(secondDateTimebegin)); // true0 |
getValueequals(dateTime)
This method gets the date and time value in the internal format.
Return:
Type | Description |
---|
null | string | The date and time value in the internal format. |
compares a datetime with an existing value to determine whether they are equal or not.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | SimpleDateTime object. | Y | N |
Return:
Type | Description |
---|
Boolean | This method returns TRUE if the date are equal; otherwise, it returns FALSE. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | equals |
---|
|
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getValue |
---|
linenumbers | true |
---|
|
const startDateTimefirstDateTime = new SimpleDateTime('20192018-01-01 08:00:00');
ss.info(startDateTime.getValue()); // 2019const secondDateTime = new SimpleDateTime('2018-01-01 08:0015:00 |
getDisplayValue()
This method gets the date and time value in the current user's display format and timezone.
Return:
Type | Description |
---|
String | The date and time value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDisplayValue |
---|
linenumbers | true |
---|
|
const startDateTime ');
const thirdDateTime = new SimpleDateTime('20192018-01-01 08:00:00');
ss.info(startDateTimefirstDateTime.getDisplayValueequals(secondDateTime)) ; // 2019-01-01 11:00:00;
ss.info(thirdDateTime.equals(firstDateTime));
//Info: false
//Info: true |
getDate()
This method returns the date stored saved by the SimpleDateTime object , showed in the system time zone.
Return:
Type | Description |
---|
String | The date in the default timezone. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDate |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDate());
//Info: 2019-01-01 |
getDaysInMonthLocalTimegetDayOfMonthLocalTime()
This method returns the number day of days in the month saved by the SimpleDateTime object , showed in the current user's time zone.
Return:
Type | Description |
---|
Integer | The |
number days
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDaysInMonthLocalTimegetDaysofMonthsLocalTime |
---|
linenumbers | true |
---|
|
const startDateTimeholidayDateTime = new SimpleDateTime('2019-01-0107 08:00:00');
ss.info(startDateTimeholidayDateTime.getDaysInMonthLocalTimegetDayOfMonthLocalTime());
//Info: 317 |
getDayOfMonthLocalTimegetDayOfMonthUTC()
This method returns the day of the month saved by the SimpleDateTime object , showed in the user's UTC time zone.
Return:
Type | Description |
---|
Integer | The day of the month value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDaysofMonthsLocalTime |
---|
linenumbers | true |
---|
|
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfMonthLocalTimegetDayOfMonthUTC());
//Info: 7 |
getDayOfMonthUTCgetDayOfWeekLocalTime()
This method returns the day of the month week saved by the SimpleDateTime object , showed in the UTC current user's time zone.
Return:
Integer the month value.week value. Possible values: 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDaysofMonthsLocalTimegetDayOfWeekLocalTime |
---|
linenumbers | true |
---|
|
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfMonthUTCgetDayOfWeekLocalTime()); // 7Mon |
getDayOfWeekLocalTimegetDayOfWeekUTC()
This method returns the day of the week saved by the SimpleDateTime object , showed in the user's system time zone.
Return:
Type | Description |
---|
String | The day of week value. Possible values: 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDayOfWeekLocalTimegetDayOfWeekUTC |
---|
linenumbers | true |
---|
|
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfWeekLocalTimegetDayOfWeekUTC());
//Info: Mon |
getDayOfWeekUTCgetDaysInMonthLocalTime()
This method returns the day number of days in the week month saved by the SimpleDateTime object , showed in the system current user's time zone.
Return:
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDayOfWeekUTCgetDaysInMonthLocalTime |
---|
linenumbers | true |
---|
|
const holidayDateTimestartDateTime = new SimpleDateTime('2019-01-0701 08:00:00');
ss.info(holidayDateTimestartDateTime.getDayOfWeekUTCgetDaysInMonthLocalTime());
//Info: Mon31 |
getDaysInMonthUTC()
This method returns the number of days in the month saved by the SimpleDateTime object , showed in the system time zone.
Return:
Type | Description |
---|
Integer | The number of days value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getDaysInMonthUTC |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDaysInMonthUTC());
//Info: 31 |
isValidgetDisplayValue()
This method allows to determine if a specified value is a valid returns the date and time . value in the current user's display format and timezone.
Return:
Boolean method returns TRUE if the value is a valid ; otherwise, it returns
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | isValidgetDisplayValue |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.setValue("2011-aagetDisplayValue()); // current user's timezone is Europe/Moscow
//Info: 2019-01-01 0011:00:00");
ss.info(startDateTime.isValid()); // false |
getErrorMsg()
This method gets returns the error message if the SimpleDateTime object was incorrect.
Return:
Type | Description |
---|
String | The error message. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getErrorMsg |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-zz-01 08:00:00');
ss.infoerror(startDateTime.getErrorMsg());
//Error: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, null given |
getLocalDate()
This method returns the date stored saved by the SimpleDateTime object , showed in the current user's time zone.
Return:
Type | Description |
---|
String | The date in the user's time zone. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getLocalDate |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getLocalDate());
//Info: 2019-01-01 |
getLocalTime()
This method returns the time saved in a SimpleDateTime object that shows the time in the in the current user's time zone .
Return:
Type | Description |
---|
SimpleDateTime | The time in the user's time zone. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getLocalTime |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const time = startDateTime.getLocalTime();
ss.info( "My local time is " + time.getByFormat('h:mi:s'));
//Info: My local time is 02:0100:00 |
getMonthLocalTime()
This method returns the month saved by SimpleDateTime object , showed in the current user's time zone.
Return:
Type | Description |
---|
String | The value of the month. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getMonthLocalTime |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getMonthLocalTime());
//Info: January |
getMonthUTC()
This method returns the month saved by SimpleDateTime object , showed in the system time zone.
Return:
Type | Description |
---|
String | The value of the month. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getMonthUTC |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getMonthUTC());
//Info: December |
getNumericValue()
This method gets returns the Unix timestamp, which stores the amount of milliseconds seconds since January 1, 1970, 00:00:00.
Return:
Type | Description |
---|
Integer | The Unix timestamp value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getNumericValue |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getNumericValue());
//Info: 1546329600 |
getTime()
This method returns a SimpleDateTime object that shows the piece of time of the SimpleDateTime object.
Return:
Type | Description |
---|
SimpleDateTime | The Unix duration stamp. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getTime |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const time = startDateTime.getTime();
ss.info(time.getByFormat('h:mi:s'));
//Info: 11:01:00 |
getWeekOfYearLocalTimegetValue()
This method returns the number of the week saved by the SimpleDateTime object, showed in the user's time-zonedate and time value in the internal format.
Return:
Integer number of the current weekdate and time value in the internal format. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getWeekOfYearLocalTimegetValue |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-1201-3101 2308:4500:00');
ss.info(startDateTime.getWeekOfYearLocalTimegetValue()); // 1 |
getWeekOfYearUTCgetWeekOfYearLocalTime()
This method returns the number of the week saved week's number saved by the SimpleDateTime object , showed in the system current user's time - zone.
Return:
Type | Description |
---|
Integer | The number of the current week. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getWeekOfYearUTCgetWeekOfYearLocalTime |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getWeekOfYearUTCgetWeekOfYearLocalTime());
//Info: 1 |
getYearLocalTimegetWeekOfYearUTC()
This method returns the year number of the week saved by the SimpleDateTime object , showed in the user's system time zone.
Return:
Four-digit year valueThe number of the current week. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getYearLocalTimegetWeekOfYearUTC |
---|
linenumbers | true |
---|
|
const holidayDateTimestartDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTimestartDateTime.getYearLocalTimegetWeekOfYearUTC());
//Info: 20201 |
getYearUTCgetYearLocalTime()
This method returns the year saved by the SimpleDateTime object , showed in the system current user's time zone.
Return:
Type | Description |
---|
Integer | Four-digit year value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getYearUTCgetYearLocalTime |
---|
linenumbers | true |
---|
|
const holidayDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTime.getYearUTCgetYearLocalTime());
//Info: 20192020 |
subtractgetYearUTC(
first, second)
This method gets the duration between to SimpleDateTime values. Also, it can subtract the amount of time from the current SimpleDateTime object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
first | SimpleDateTime Object | Y | N |
first | SimpleTime Object | Y | N |
first | Number (milliseconds) | Y | N |
second | SimpleDateTime Object | N | NULL |
second | SimpleTime Object | N | NULL |
second | Number (milliseconds) | N | NULL |
returns the year saved by the SimpleDateTime object in the system time zone.
Return:
Type | Description |
---|
Integer | Four-digit year value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | getYearUTC |
---|
linenumbers | true |
---|
|
const holidayDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTime.getYearUTC());
//Info: 2019 |
isValid()
This method allows to determine if a specified value is a valid date and time.
Return:
Type | Description |
---|
Boolean | The method returns TRUE if the value is a valid date and time; otherwise, it returns . |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | isValid |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
startDateTime.setValue('2011-aa-01 00:00:00');
ss.info(startDateTime.isValid());
//Info: false |
setValue(dateTime)
This method is intended to define the date and time value within the SimpleDateTime object.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
dateTime | A string in the UTC timezone and the internal format of YYYY-MM-DD hh:mm:ss. | Y | N |
dateTime | A SimpleDateTime object. | Y | N |
dateTime | A JavaScript Number. It sets the value of the object using the Number value as milliseconds past January 1, 1970, 00:00:00. | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | setValue |
---|
linenumbers | true |
---|
|
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
startDateTime.setValue('2020-01-01 12:00:00');
ss.info(startDateTime.getValue());
//Info: 2020-01-01 12:00:00 |
subtract(first, second)
This method returns the amount of time between two SimpleDateTime values. Also, it can subtract the amount of time from the current SimpleDateTime object.
Note |
---|
Displaying of the final value using the getDisplayValue() method returns it considering the current user' timezone, unlike the getValue() method. It returns data only in UTC timezone. |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
first | SimpleDateTime Object | Y | N |
second | SimpleDateTime Object | N | NULL |
Return:
Type |
---|
SimpleDuration object |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | subtract #1 |
---|
linenumbers | true |
---|
|
const startDatetime = new SimpleDateTime('2019-11-08 20:00:00');
const endDatetime = new SimpleDateTime('2019-11-08 20:06:28');
const diffDuration = new SimpleDateTime().subtract(startDatetime, endDatetime);
ss.info(diffDuration.getDurationSeconds());
// Info: 388 |
Same example without using of the subtract:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
linenumbers | true |
---|
|
const startDatetime = new SimpleDateTime('2019-11-08 20:00:00');
const endDatetime = new SimpleDateTime('2019-11-08 20:06:28');
const diffSeconds = endDatetime.getNumericValue() - startDatetime.getNumericValue();
ss.info(diffSeconds);
// Info: 388 |
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | subtract #2 |
---|
linenumbers | true |
---|
|
const datetime = new SimpleDateTime('2020-08-28 09:00:00');
datetime.subtract(3600);
ss.info(datetime.getValue());
//Info: 2020-08-28 08:00:00 |
Same example without using of the subtract
Return:
Type |
---|
SimpleDuration object |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | subtract #2 |
---|
linenumbers | true |
---|
|
const startDateTimedatetime = new SimpleDateTime("2019-01-01 08:00:00");
const periodTime = new SimpleTime();
periodTime.setValue("00:00:20");
startDateTime.subtract(periodTime);
const afterSutractDateTime = startDateTime.getTime();
ss.info(afterSutractDateTime.getByFormat('h:m:s')); // 01:12:40('2020-08-28 09:00:00');
datetime.addSeconds(-3600);
ss.info(datetime.getValue());
//Info: 2020-08-28 08:00:00 |