Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This class provides methods for performing operations on SimpleDateTime objects, such as instantiating objects, for example.
You can also use this class to perform date-time operations, such as calculations, formatting or converting between date-time formats.
SimpleDateTime(dateTime)
Instantiates a new SimpleDateTime object with the current date and time.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
dateTime | String | N | '' |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst nowDateTime = new SimpleDateTime(); // const registrationDateTime = new SimpleDateTime(record.registration_datetime); // const yearStartDateTime = new SimpleDateTime('2019-01-01 0800:00:00'); |
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.
The 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst registrationDateTime = new SimpleDateTime('2019-01-01 08:0012:0010'); simple_date_timeregistrationDateTime.addDays(-13); ss.info(simple_date_timeregistrationDateTime.getValue()); // 20182019-1201-3104 08:0012:0010 |
addMonths(months)
This method adds a specified number of months to the current SimpleDateTime object. The negative 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 values.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
months | Integer | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst registrationDateTime = new SimpleDateTime('2019-01-01 08:0012:0010'); simple_date_timeregistrationDateTime.addMonths(-1) ss.info(simple_date_timeregistrationDateTime.getValue()); // 2018-12-01 08:0012:0010 |
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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst registrationDateTime = new SimpleDateTime('2019-01-01 08:0012:0010'); simple_date_timeregistrationDateTime.addSeconds(3600); ss.info(simple_date_timeregistrationDateTime.getValue()); // 2019-01-01 09:0012:0010 |
addWeeks(weeks)
This method adds a specified number of weeks to the current SimpleDateTime object. The negative 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 values.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
weeks | Integer | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst registrationDateTime = new SimpleDateTime('2019-01-01 08:0012:0010'); simple_date_timeregistrationDateTime.addWeeks(-1); ss.info(simple_date_timeregistrationDateTime.getValue()); // 20182019-1201-2508 08:0012:0010 |
addYears(years)
This method adds a specified number of years to the current SimpleDateTime object. The negative 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 values.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
years | Integer | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst contractStartDateTime = new SimpleDateTime('2019-01-01 0800:00:00'); simple_date_timecontractStartDateTime.addYears(1); ss.info(simple_date_timecontractStartDateTime.getValue()); // 2020-01-01 0800: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 after the specified; otherwise returns FALSE.
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 later than the date specified by the parameter; otherwise, returns FALSE. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_timeconst startDateTime = new SimpleDateTime('20192018-01-01 0807:0058:0035'); var second_simple_date_timeconst endDateTime = new SimpleDateTime('20182019-01-01 08:00:00'); letconst resultisStartLaterThanEnd = first_simple_date_time startDateTime.after(second_simple_date_timeendDateTime); ss.info(resultisStartLaterThanEnd); // truefalse |
before(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 the specified; otherwise returns false.
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 than the date specified by the parameter; otherwise, returns FALSE. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_timeconst startDateTime = new SimpleDateTime('20192018-01-01 0807:0058:0035'); var second_simple_date_timeconst endDateTime = new SimpleDateTime('20182019-01-01 08:00:00'); letconst resultisStartBeforeEnd = first_simple_date_timestartDateTime.before(second_simple_date_timeendDateTime); ss.info(resultisStartBeforeEnd); // falsetrue |
compareTo(dateTime)
This method compares two date and time objects to determine whether they are equivalent or not.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
dateTime | SimpleDateTime object | Y | N |
Return:
Type | Description |
---|---|
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. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_timeconst firstDateTime = new SimpleDateTime('2019-01-01 08:00:00'); var second_simple_date_timeconst secondDateTime = new SimpleDateTime('2018-01-01 08:00:00'); var third_simple_date_timeconst thirdDateTime = new SimpleDateTime('2018-01-01 08:00:00'); ss.info( first_simple_date_timethirdDateTime.compareTo(second_simple_date_time) secondDateTime )); // 10 ss.info( second_simple_date_timefirstDateTime.compareTo(first_simple_date_time) secondDateTime)); // -1 ss.info( third_simple_date_timesecondDateTime.compareTo(second_simple_date_time ) firstDateTime)); // 0-1 |
equals(dateTime)
This method compares a datetime with an existing value if they are equal.
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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_timeconst firstDateTime = new SimpleDateTime('2019-01-01 08:00:00'); var second_simple_date_timeconst secondDateTime = new SimpleDateTime('2018-01-01 08:00:00'); var third_simple_date_timeconst thirdDateTime = new SimpleDateTime('2018-01-01 08:00:00'); ss.info( first_simple_date_timefirstDateTime.equals(second_simple_date_time) secondDateTime)); // 0false ss.info( third_simple_date_timethirdDateTime.equals(second_simple_date_time ) secondDateTime)); // 1true |
getDate()
This method returns the date stored by the SimpleDateTime object, showed in the system time zone.
Return:
Type | Description |
---|---|
String | The date in the default timezone. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst startDateTime = new SimpleDateTime('2019-01-01 08:00:00'); ss.info(simple_date_timestartDateTime.getDate() ); // 2019-01-01 |
getDaysInMonthLocalTime()
This method returns the number of days in the month saved by the SimpleDateTime object, showed in the user's time zone.
Return:
Type | Description |
---|---|
Integer | The number of days value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst startDateTime = new SimpleDateTime('2019-01-01 08:00:00'); ss.info(simple_date_timestartDateTime.getDaysInMonthLocalTime() ); // 31 |
getDayOfMonthLocalTime()
This method returns the day of the month saved by the SimpleDateTime object, showed in the user's time zone.
Return:
Type | Description |
---|---|
Integer | The day of the month value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst holidayDateTime = new SimpleDateTime('2019-01-0107 08:00:00'); ss.info(simple_date_time(holidayDateTime.getDayOfMonthLocalTime() ); // 17 |
getDayOfMonthUTC()
This method returns the day of the month saved by the SimpleDateTime object, showed in the UTC time zone.
Return:
Type | Description |
---|---|
Integer | The day of the month value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst holidayDateTime = new SimpleDateTime('2019-01-0107 08:00:00'); ss.info(simple_date_timeholidayDateTime.getDayOfMonthUTC() ); // 17 |
getDayOfWeekLocalTime()
This method returns the day of the week saved by the SimpleDateTime object, showed in the user's time zone.
Return:
Type | Description |
---|---|
String | The day of week value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst holidayDateTime = new SimpleDateTime('2019-01-0107 08:00:00'); ss.info(simple_date_timeholidayDateTime.getDayOfWeekLocalTime() ); // TueMon |
getDayOfWeekUTC()
This method returns the day of the week saved by the SimpleDateTime object, showed in the system time zone.
Return:
Type | Description |
---|---|
String | The day of week value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst holidayDateTime = new SimpleDateTime('2019-01-0107 08:00:00'); ss.info(simple_date_timeholidayDateTime.getDayOfWeekUTC() ); // TueMon |
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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info(simple_date_time.getDaysInMonthUTC() ); // 31 |
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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info( simple_date_time.getDisplayValue() ) ; // 2019-01-01 11:00:00 |
getErrorMsg()
This method gets the error message if the SimpleDateTime object was incorrect.
Return:
Type | Description |
---|---|
String | The error message. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-zz-01 08:00:00'); ss.info(simple_date_time.getErrorMsg() ) ; |
getLocalDate()
This method returns the date stored by the SimpleDateTime object, showed in the user's time zone.
Return:
Type | Description |
---|---|
String | The date in the user's time zone. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info(simple_date_time.getLocalDate() ) // 2019-01-01 |
getLocalTime()
This method returns a SimpleDateTime object that shows the time in the user's time zone.
Return:
Type | Description |
---|---|
SimpleDateTime | The time in the user's time zone. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); var time = first_simple_date_time.getLocalTime(); ss.info( "My local time is " + time.getByFormat('h:m:s') ) ; // My local time is 02:01: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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info(simple_date_time.getMonthLocalTime() ); // 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info( first_simple_date_time.getMonthUTC() ); // January |
getNumericValue()
This method gets the timestamp which stores the amount of milliseconds since January 1, 1970, 00:00:00.
Return:
Type | Description |
---|---|
Integer | The timestamp value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info(simple_date_time.getNumericValue() ) ; // 1546318800 |
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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); var time = first_simple_date_time.getTime(); ss.info( time.getByFormat('h:m:s') ); // 11:01:00 |
getValue()
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. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info( first_simple_date_time.getValue() ); //2019-01-01 08:00:00 |
getWeekOfYearLocalTime()
This method returns the number of the week saved by the SimpleDateTime object, showed in the user's time-zone.
Return:
Type | Description |
---|---|
Integer | The number of the current week. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info( first_simple_date_time.getWeekOfYearLocalTime() ); // 1 |
getWeekOfYearUTC()
This method returns the number of the week saved by the SimpleDateTime object, showed in the system time-zone.
Return:
Type | Description |
---|---|
Integer | The number of the current week. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); ss.info( first_simple_date_time.getWeekOfYearUTC() ); // 1 |
getYearLocalTime()
This method returns the year saved by the SimpleDateTime object, showed in the user's time zone.
Return:
Type | Description |
---|---|
Integer | Four-digit year value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_timeconst holidayDateTime = new SimpleDateTime('2019-0112-0131 0823:0045:00'); ss.info( first_simple_date_timeholidayDateTime.getYearLocalTime()); // 20192020 |
getYearUTC()
This method returns the year saved by the SimpleDateTime object, showed in the system time zone.
Return:
Type | Description |
---|---|
Integer | Four-digit year value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var first_simple_date_timeconst holidayDateTime = new SimpleDateTime("'2019-0112-0131 0823:0045:00"'); ss.info( first_simple_date_timeholidayDateTime.getYearUTC() ); // 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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_time = new SimpleDateTime('2019-01-01 08:00:00'); simple_date_time.setDisplayValue("2011-aa-01 00:00:00"); ss.info(simple_date_time.isValid() ) ; // false |
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. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst startDateTime = new SimpleDateTime('"2019-01-01 08:00:00'"); simple_date_timestartDateTime.setValue('2020-01-01 12:00:00'); ss.info(simple_date_timestartDateTime.getValue() ); // 2020-01-01 12:00:00 |
subtract(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 |
Return:
Type |
---|
SimpleDuration object |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var simple_date_timeconst startDateTime = new SimpleDateTime("2019-01-01 08:00:00"); varconst simple_timeperiodTime = new SimpleTime(); simple_timeperiodTime.setValue("00:00:20"); simple_date_timestartDateTime.subtract(simple_timeperiodTime); var second_simple_time const afterSutractDateTime = simple_date_timestartDateTime.getTime(); ss.info( second_simple_timeafterSutractDateTime.getByFormat('h:m:s') ); // 01:12:40 |
Table of Contents | ||||
---|---|---|---|---|
|