Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Use this This class provides methods to conduct operations on SimpleDateTime objects, for example, instantiating : instantiate objects, and to calculate, change formats of the date and time formats, or convert between the formatsthem.

SimpleDateTime(dateTime)


Use this constructor to instantiate a new SimpleDateTime object with the current or transferred date and time. Since the object keeps date and time in the UTC timezone, ensure the data you pass to the object is in UTC, otherwise your results will be invalid.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
dateTimeStringN''

Example:

Code Block
languagejs
themeEclipse
titleSimpleDateTime()
linenumberstrue
const nowDateTime = new SimpleDateTime();
//
const registrationDateTime = new SimpleDateTime(record.registration_datetime);
//
const yearStartDateTime = new SimpleDateTime('2019-01-01 00:00:00');

You can also use the values in relative format for the SimpleDateTime constructor. All formats are available in the Relative Formats article.

Code Block
languagejs
themeEclipse
titleSimpleDateTime()
linenumberstrue
const yesterdayDatetime = new SimpleDateTime('yesterday');
ss.info(yesterdayDatetime.getValue());
// Info: 2022-02-28 00:00:00  

const tomorrowDatetime = new SimpleDateTime('tomorrow');
ss.info(tomorrowDatetime.getValue());
// Info: 2022-03-02 00:00:00

const yesterdayWorkdayDayStart = new SimpleDateTime('yesterday 06:30');
ss.info(yesterdayWorkdayDayStart.getValue());
// Info: 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(`first day of ${monthName}`);
ss.info(rangeStartDatetime .getValue());
// Info: 2022-02-01 00: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)


Use this method 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 days.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
daysintegerYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titleaddDays()
linenumberstrue
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addDays(3);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-04 08:12:10

addMonths(months)


Use this method to change the number of months in the current SimpleDateTime object according to the local current date and time. The positive value of the parameter adds months the number of days equal to the number of days in this month to the objectdate, the negative value diminishes subtracts the number of days equal to the number of monthsdays in the previous month from the date.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
monthsIntegerYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titleaddMonths()
linenumberstrue
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addMonths(-1);
ss.info(registrationDateTime.getValue());
//Info: 2018-12-01 08:12:10

addSeconds(seconds)


This Use this method is used to change the number of seconds in the current SimpleDateTime object according to the local date and timelocal time. The positive value of the parameter adds seconds to the object, the negative value diminishes the number of seconds.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
secondsIntegerYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titleaddSeconds()
linenumberstrue
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addSeconds(3600);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-01 09:12:10

addWeeks(weeks)


This Use this method is used to change the number of weeks in the current SimpleDateTime object according to the local date and time. The positive value of the parameter adds weeks to the object, the negative value diminishes the number of weeks.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
weeksIntegerYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titleaddWeeks()
linenumberstrue
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addWeeks(1);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-08 08:12:10

addYears(years)


This Use this method is 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):

NameTypeMandatoryDefault Valuevalue
yearsIntegerYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titleaddYears()
linenumberstrue
const contractStartDateTime = new SimpleDateTime('2019-01-01 00:00:00');
contractStartDateTime.addYears(1);
ss.info(contractStartDateTime.getValue());
//Info: 2020-01-01 00:00:00

after(dateTime)


Use this method to compare the date specified by the dateTime parameter with the current date. 

Parameter(s):

NameTypeMandatoryDefault Valuevalue
dateTimeSimpleDateTime objectYN

Return:

TypeDescription
BooleanThe method returns true if the current date is later than the date specified by the parameter; otherwise, it returns false.

Example:

Code Block
languagejs
themeEclipse
titleafter()
linenumberstrue
const startDateTime = new SimpleDateTime('2018-01-01 07:58:35');
const endDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const isStartAfterThanEnd = startDateTime.after(endDateTime);
ss.info(isStartAfterThanEnd);
//Info: false

before(dateTime)


Use this method to compare the date specified by the dateTime parameter with the current date.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
dateTimeSimpleDateTime objectYN

Return:

TypeDescription
BooleanThe method returns true if the current date is earlier than the date specified by the parameter; otherwise, it returns false.

Example:

Code Block
languagejs
themeEclipse
titlebefore()
linenumberstrue
const startDateTime = new SimpleDateTime('2018-01-01 07:58:35');
const endDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const isStartBeforeEnd = startDateTime.before(endDateTime);
ss.info(isStartBeforeEnd);
//Info: true

compareTo(dateTime)


This Use this method compares to compare two date and time objects to and determine whether they are equal and, if . If not, the method defines which goes after or before the other.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
dateTimeSimpleDateTime objectYN

Return:

TypeDescription
0The dates are equal.
1The object's date is after the date specified in the parameter.
-1The object's date is before the date specified in the parameter.

Example:

Code Block
languagejs
themeEclipse
titlecompareTo()
linenumberstrue
const begin = new SimpleDateTime('2019-04-01 08:15:00');
const end = new SimpleDateTime('2019-05-01 01:00:00');

ss.info(begin.compareTo(end));   // -1
ss.info(end.compareTo(begin));   // 1
ss.info(begin.compareTo(begin)); // 0

equals(dateTime)


This method compares a datetime Use this method to compare date and time objects with an existing value value to determine whether they are equal.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
dateTimeSimpleDateTime object.YN

Return:

TypeDescription
BooleanThis method returns true if the dates date and time objects are equal; otherwise, it returns false.

Example:

Code Block
languagejs
themeEclipse
titleequals()
linenumberstrue
const firstDateTime = new SimpleDateTime('2018-01-01 08:00:00');
const secondDateTime = new SimpleDateTime('2018-01-01 08:15:00');
const thirdDateTime = new SimpleDateTime('2018-01-01 08:00:00');

ss.info(firstDateTime.equals(secondDateTime));
ss.info(thirdDateTime.equals(firstDateTime));
//Info: false
//Info: true

getDate()


This Use this method returns to return the date saved by the SimpleDateTime object in the system UTC timezone.

Return:

TypeDescription
StringThe This method returns the date in the default UTC timezone.

Example:

Code Block
languagejs
themeEclipse
titlegetDate()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDate());
//Info: 2019-01-01

getDayOfMonthLocalTime()


This Use this method returns to return the day of the month saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
IntegerThe This method returns the day of the month value.

Example:

Code Block
languagejs
themeEclipse
titlegetDaysofMonthsLocalTime()
linenumberstrue
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfMonthLocalTime());
//Info: 7

getDayOfMonthUTC()


This Use this method returns to return the day of the month saved by the SimpleDateTime object in the UTC timezone.

Return:

TypeDescription
IntegerThe This method returns the day of the month value.

Example:

Code Block
languagejs
themeEclipse
titlegetDaysofMonthsLocalTime()
linenumberstrue
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfMonthUTC());
//Info: 7

getDayOfWeekLocalTime()


This Use this method returns to return the day of the week saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
StringThe This method returns the day of week value. Possible values: 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' .

Example:

Code Block
languagejs
themeEclipse
titlegetDayOfWeekLocalTime()
linenumberstrue
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfWeekLocalTime()); // Mon

getDayOfWeekUTC()


This Use this method returns to return the day of the week saved by the SimpleDateTime object in the system timezone.

Return:

TypeDescription
StringThe This method returns the day of the week value.
Possible values: 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'. 

Example:

Code Block
languagejs
themeEclipse
titlegetDayOfWeekUTC()
linenumberstrue
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfWeekUTC());
//Info: Mon

getDaysInMonthLocalTime()


This Use this method returns to return the number of days in the month saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
IntegerThe This method returns the number of days valuein a month.

Example:

Code Block
languagejs
themeEclipse
titlegetDaysInMonthLocalTime()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDaysInMonthLocalTime());
//Info: 31

getDaysInMonthUTC()


This Use this method returns to return the number of days in the month saved by the SimpleDateTime object in the system timezone.

Return:

TypeDescription
IntegerThe This method returns the number of days value.

Example:

Code Block
languagejs
themeEclipse
titlegetDaysInMonthUTC()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDaysInMonthUTC());
//Info: 31

getDisplayValue()


This Use this method returns to return the date and time value in the current user's display format and timezone.

Return:

TypeDescription
StringThe This method returns the date and time value.

Example:

Code Block
languagejs
themeEclipse
titlegetDisplayValue()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDisplayValue()); // current user's timezone is Europe/Moscow
//Info: 2019-01-01 11:00:00 

getErrorMsg()


This Use this method returns to return the error message if the SimpleDateTime object is incorrect.

Return:

TypeDescription
StringThe This method returns the error message.

Example:

Code Block
languagejs
themeEclipse
titlegetErrorMsg()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-zz-01 08:00:00');
ss.error(startDateTime.getErrorMsg());
//Error: The parsed date or time was invalid!

getLocalDate()


This Use this method returns to return the date saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
StringThe This method returns the date in the user's timezone.

Example:

Code Block
languagejs
themeEclipse
titlegetLocalDate()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getLocalDate());
//Info: 2019-01-01

getLocalTime()


This Use this method returns to return the time saved in a SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
SimpleDateTime objectThe This method returns the time in the user's timezone.

Example:

Code Block
languagejs
themeEclipse
titlegetLocalTime()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const time = startDateTime.getLocalTime();
ss.info( "My local time is " + time.getByFormat('h:i:s'));
//Info: My local time is 02:00:00

getMonthLocalTime()


This Use this method returns to return the month saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
StringThe value This method returns the name of the month.

Example:

Code Block
languagejs
themeEclipse
titlegetMonthLocalTime()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getMonthLocalTime());
//Info: January

getMonthUTC()


This Use this method returns to return the month saved by SimpleDateTime object in the system UTC timezone.

Return:

TypeDescription
StringThe value This method returns the name of the month.

Example:

Code Block
languagejs
themeEclipse
titlegetMonthUTC()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getMonthUTC());
//Info: December

getNumericValue()


This Use this method returns to return the Unix timestamp that stores the amount of seconds since January 1, 1970, 00:00:00.

Return:

TypeDescription
IntegerThe This method returns the Unix timestamp value.

Example:

Code Block
languagejs
themeEclipse
titlegetNumericValue()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getNumericValue());
//Info: 1546329600

getTime()


This Use this method returns to return a SimpleDateTime object that shows the piece of time value of the SimpleDateTime object.

Return:

TypeDescription
SimpleDateTime objectThe This method returns the Unix duration stamp.

Example:

Code Block
languagejs
themeEclipse
titlegetTime()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const time = startDateTime.getTime();
ss.info(time.getByFormat('h:i:s'));
//Info: 11:01:00

getValue()


This Use this method returns to return the date and time value in the internal format.

Return:

TypeDescription
String or nullThis method returns the The date and time value in the internal format. If the date value is invalid, the method returns returns null.

Example:

Code Block
languagejs
themeEclipse
titlegetValue()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getValue()); // 2019-01-01 08:00:00

getWeekOfYearLocalTime()


This Use this method returns to return the week's number saved number saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
IntegerThe This method returns the number of the current week.

Example:

Code Block
languagejs
themeEclipse
titlegetWeekOfYearLocalTime
linenumberstrue
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getWeekOfYearLocalTime());
//Info: 1

getWeekOfYearUTC()


This Use this method returns to return the number of the week saved by the SimpleDateTime object in the system UTC timezone.

Return:

TypeDescription
IntegerThe This method returns the number of the current week.

Example:

Code Block
languagejs
themeEclipse
titlegetWeekOfYearUTC()
linenumberstrue
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getWeekOfYearUTC());
//Info: 1

getYearLocalTime()


This Use this method returns to return the year saved by the SimpleDateTime object in the current user's timezone.

Return:

TypeDescription
IntegerFourThis method returns the four-digit year value.

Example:

Code Block
languagejs
themeEclipse
titlegetYearLocalTime()
linenumberstrue
const holidayDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTime.getYearLocalTime());
//Info: 2020

getYearUTC()


This Use this method returns to return the year saved by the SimpleDateTime object in the system timezone.

Return:

TypeDescription
IntegerFourThis method returns the four-digit year value.

Example:

Code Block
languagejs
themeEclipse
titlegetYearUTC()
linenumberstrue
const holidayDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTime.getYearUTC()); 
//Info: 2019

isValid()


Use this method to check whether the specified date and time values are valid.

Return:

TypeDescription
BooleanThe method returns true if the value is a valid date and time; otherwise, it returns false.

Example:

Code Block
languagejs
themeEclipse
titleisValid()
linenumberstrue
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)


Use this method to define the date and time value within the SimpleDateTime object.

Parameter(s):

NameTypeMandatoryDefault ValuedateTimeA string

The value of the dateTime parameter should be in the UTC timezone and the internal format of YYYY-MM-DD hh:mm:ss.

Parameter(s):

A JavaScript Number. It sets the value of the object using the Number value as milliseconds past January 1, 1970, 00:00:00.
NameTypeMandatoryDefault value
dateTimeString
YN
dateTimeA SimpleDateTime object.YN
dateTimeYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titlesetValue()
linenumberstrue
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 Use this method returns to return the amount of time between two SimpleDateTime values. Also, it can subtract the amount of time from the current SimpleDateTime object.

Note

The getDisplayValue() method returns the value in the user's timezone. The getValue() method returns data only in the UTC timezone.

Parameter(s):

NameTypeMandatoryDefault Valuevalue
first

SimpleDateTime Objectobject/Integer

YN
secondSimpleDateTime ObjectobjectNNULLnull

Return:

TypeDescription
SimpleDuration object or nullThe method returns SimpleDuration object if both parameters were passed to the method. Otherwise, the method returns null.

Example 1:

Code Block
languagejs
themeEclipse
titlesubtract #1
linenumberstrue
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 the subtract:

Code Block
languagejs
themeEclipse
linenumberstrue
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

Example 2:

Code Block
languagejs
themeEclipse
titlesubtract #2
linenumberstrue
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 the subtract:

Code Block
languagejs
themeEclipsetitlesubtract #2
linenumberstrue
const datetime = new SimpleDateTime('2020-08-28 09:00:00');
datetime.addSeconds(-3600);
ss.info(datetime.getValue());
//Info: 2020-08-28 08:00:00


Table of Contents
absoluteUrltrue