GlideDateTime - Global
-
- UpdatedJan 30, 2025
- 27 minutes to read
- Yokohama
- API reference
The GlideDateTime class provides methods for performing operations on GlideDateTime objects.
Use the GlideDateTime methods to perform date-time operations, such as instantiating a GlideDateTime object, performing date-time calculations, formatting a date-time, or converting between date-time formats.
For guidance on date time input strings with a list of common format conflicts, refer to Date and time format guidelines.
GlideDateTime - GlideDateTime()
Instantiates a new GlideDateTime object with the current date and time.
Name | Type | Description |
---|---|---|
None |
Example
This example instantiates a GlideDateTime object.
Output:
GlideDateTime - GlideDateTime(String dateTime)
Instantiates a new GlideDateTime object using the passed-in date and time value.
- yyyy-MM-dd HH:mm:ss
- MM/dd/yyyy HH:mm:ss
- MM-dd-yyyy HH:mm:ss
- MM-dd-yyyy HH:mm
- MM-dd-yyyy
- MM/dd/yyyy
- dd-MM-yyyy HH:mm:ss
- dd-MM-yyyy HH.mm.ss
- dd-MM-yyyy HH.mm
- dd-MM-yy HH.mm.ss
- dd/MM/yyyy
- dd-MM-yyyy
- yyyy-MM-dd HH:mm
- yyyy-MM-dd
- dd.MM.yyyy HH:mm:ss
- dd.MM.yyyy HH.mm.ss
- dd.MM.yyyy hh:mm:ss a
- dd.MM.yyyy hh.mm.ss a
- dd.MM.yyyy
- yyyy-MM-dd'T'HH:mm:ss.SSSZ
Name | Type | Description |
---|---|---|
dateTime | String | UTC date and time to set in the GlideDateTime object. |
Example
This example shows how to instantiate a GlideDateTime object using a string.
Output:
GlideDateTime - GlideDateTime(GlideDateTime gdt)
Instantiates a new GlideDateTime object set to the time of a specified GlideDateTime object.
Name | Type | Description |
---|---|---|
gdt | GlideDateTime | Object used to set the time of the new object. |
Example
This example shows how to instantiate a GlideDateTime object (gdt1) using a string in the format yyyy-MM-dd HH:mm:ss
, and a second GlideDateTime object (gdt2) using
gdt1.
Output:
GlideDateTime - add(Number milliseconds)
Adds a specified number of milliseconds to the GlideDateTime object.
Name | Type | Description |
---|---|---|
milliseconds | Number | The number of milliseconds to add |
Type | Description |
---|---|
void |
Example
Scoped equivalent
To use the add() method in a scoped application, use the corresponding scoped method: add().
GlideDateTime - add(GlideTime time)
Adds a GlideTime object to the current GlideDateTime object.
Name | Type | Description |
---|---|---|
time | GlideTime | GlideTime object whose time value to add to the specified GlideDateTime object. |
Type | Description |
---|---|
void |
Example
This example shows how to add 20 seconds to the time set in the gdt GlideDateTime object.
Output:
Scoped equivalent
To use the add() method in a scoped application, use the corresponding scoped method: add().
GlideDateTime - addDays(Number days)
Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.
Use addDaysLocalTime() and addDaysUTC() instead of this method.
Name | Type | Description |
---|---|---|
days | Number | The number of days to add. Use a negative number to subtract. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - addDaysLocalTime(Number days)
Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.
The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts days using the local date and time values.
Name | Type | Description |
---|---|---|
days | Number | The number of days to add. Use a negative value to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addDaysLocalTime() method in a scoped application, use the corresponding scoped method: addDaysLocalTime().
GlideDateTime - addDaysUTC(Number days)
Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.
The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts days using the UTC date and time values.
Name | Type | Description |
---|---|---|
days | Number | The number of days to add. Use a negative value to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addDaysUTC() method in a scoped application, use the corresponding scoped method: addDaysUTC().
GlideDateTime - addSeconds(Number seconds)
Adds a specified number of seconds to the GlideDateTime object.
Name | Type | Description |
---|---|---|
seconds | Number | The number of seconds to add |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addSeconds() method in a scoped application, use the corresponding scoped method: addSeconds().
GlideDateTime - addWeeks(Number weeks)
Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.
Use addWeeksLocalTime() and addWeeksUTC() instead of this method.
Name | Type | Description |
---|---|---|
weeks | Number | The number of weeks to add. Use a negative number to subtract. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - addWeeksLocalTime(Number weeks)
Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.
The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts weeks using the local date and time values.
Name | Type | Description |
---|---|---|
weeks | Number | The number of weeks to add. Use a negative number to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addWeeksLocalTime() method in a scoped application, use the corresponding scoped method: addWeeksLocalTime().
GlideDateTime - addWeeksUTC(Number weeks)
Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.
The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts weeks using the UTC date and time values.
Name | Type | Description |
---|---|---|
weeks | Number | The number of weeks to add. Use a negative number to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addWeeksUTC() method in a scoped application, use the corresponding scoped method: addWeeksUTC().
GlideDateTime - addMonths(Number months)
Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.
Use addMonthsLocalTime() or addMonthsUTC() instead of this method.
Name | Type | Description |
---|---|---|
months | Number | The number of months to add. Use a negative number to subtract. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - addMonthsLocalTime(Number months)
Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.
The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts months using the local date and time values.
Name | Type | Description |
---|---|---|
months | Number | The number of months to add. Use a negative value to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addMonthsLocalTime() method in a scoped application, use the corresponding scoped method: addMonthsLocalTime().
GlideDateTime - addMonthsUTC(Number months)
Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.
The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts months using the UTC date and time values.
Name | Type | Description |
---|---|---|
months | Number | The number of months to add. Use a negative number to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addMonthsUTC() method in a scoped application, use the corresponding scoped method: addMonthsUTC().
GlideDateTime - addYears(Number years)
Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.
Use addYearsLocalTime() or addYearsUTC() instead of this method.
Name | Type | Description |
---|---|---|
years | Number | The number of years to add. Use a negative value to subtract. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - addYearsLocalTime(Number years)
Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.
The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts years using the local date and time values.
Name | Type | Description |
---|---|---|
years | Number | The number of years to add. To subtract use a negative value. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the AddYearsLocalTime() method in a scoped application, use the corresponding scoped method: AddYearsLocalTime().
GlideDateTime - addYearsUTC(Number years)
Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.
The date and time value stored by GlideDateTime object is interpreted as being in the UTC time zone.
Name | Type | Description |
---|---|---|
years | Number | The number of years to add. Use a negative value to subtract. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the addYearsUTC() method in a scoped application, use the corresponding scoped method: addYearsUTC().
GlideDateTime - compareTo(Object dateTime)
Compares two date and time objects to determine whether one occurs before the other or if they are equivalent.
Name | Type | Description |
---|---|---|
dateTime | Object | Date time in a GlideDateTime object |
Type | Description |
---|---|
Number |
|
Example
Output:
Scoped equivalent
To use the compareTo() method in a scoped application, use the corresponding scoped method: compareTo().
GlideDateTime - equals(Object GDT)
Compares an object with an existing value for equality.
Name | Type | Description |
---|---|---|
GDT | Object | The object to compare. Can be a GlideDateTIme object or a valid date time string. |
Type | Description |
---|---|
Boolean | True if they are equal, false otherwise. |
Example
Output:
Scoped equivalent
To use the equals() method in a scoped application, use the corresponding scoped method: equals().
GlideDateTime - getDate()
Returns the date stored by the GlideDateTime object. Expressed in the format yyyy-MM-dd and in the system time zone, UTC by default.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Date in the system time zone. Format: yyyy-MM-dd, and in the system time zone, UTC by default. |
Example
Output:
Scoped equivalent
To use the getDate() method in a scoped application, use the corresponding scoped method: getDate().
GlideDateTime - getDayOfMonth()
Gets the current day of the month in the UTC time zone.
Deprecated. Use getDayOfMonthLocalTime() and getDayOfMonthUTC() instead of this method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The day of the month in the UTC time zone, from 1 to 31. |
Example
Output:
GlideDateTime - getDayOfMonthLocalTime()
Gets the day of the month stored by the GlideDateTime object, expressed in the current user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The day of the month in the user's time zone, from 1 to 31. |
Example
Output:
Scoped equivalent
To use the getDayOfMonthLocalTime() method in a scoped application, use the corresponding scoped method: getDayOfMonthLocalTime().
GlideDateTime - getDayOfMonthUTC()
Gets the day of the month stored by the GlideDateTime object, expressed in the UTC time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The day of the month in the UTC time zone, from 1 to 31. |
Example
Output:
Scoped equivalent
To use the getDayOfMonthUTC() method in a scoped application, use the corresponding scoped method: getDayOfMonthUTC().
GlideDateTime - getDayOfWeek()
Retrieves the day of the week stored by the GlideDateTime object, expressed in the user's time zone.
Use getDayOfWeekLocalTime() and getDayOfWeekUTC() instead of this method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The day of the week value - Monday = 1, ... Sunday = 7. |
Example
Output:
GlideDateTime - getDayOfWeekLocalTime()
Gets the day of the week stored by the GlideDateTime object, expressed in the user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The day of the week value - Monday = 1, ... Sunday = 7 |
Example
Output:
Scoped equivalent
To use the getDayOfWeekLocalTime() method in a scoped application, use the corresponding scoped method: getDayOfWeekLocalTime().
GlideDateTime - getDayOfWeekUTC()
Gets the day of the week stored by the GlideDateTime object, expressed in the UTC time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The day of the week value - Monday = 1, ... Sunday = 7 |
Example
Output:
Scoped equivalent
To use the getDayOfWeekUTC() method in a scoped application, use the corresponding scoped method: getDayOfWeekUTC().
GlideDateTime - getDaysInMonth()
Gets the number of days in the month stored by the GlideDateTime object, expressed in the Java Virtual Machine time zone.
Use getDaysInMonthLocalTime() and getDaysInMonthUTC() instead of this method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of days in the current month in the Java Virtual Machine time zone. |
Example
Output:
GlideDateTime - getDaysInMonthLocalTime()
Gets the number of days in the month stored by the GlideDateTime object, expressed in the current user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of days in the current month in the user's time zone. |
Example
Output:
Scoped equivalent
To use the getDaysInMonthLocalTime() method in a scoped application, use the corresponding scoped method: getDaysInMonthLocalTime().
GlideDateTime - getDaysInMonthUTC()
Gets the number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone. |
Example
Output:
Scoped equivalent
To use the getDaysInMonthUTC() method in a scoped application, use the corresponding scoped method: getDaysInMonthUTC().
GlideDateTime - getDisplayValue()
Gets the date and time value in the current user's display format and time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | Date and time in the user's format and time zone. Keep in mind when designing business rules or script includes that this method may return values in different formats for different users. |
Example
Output:
Scoped equivalent
To use the getDisplayValue() method in a scoped application, use the corresponding scoped method: getDisplayValue().
GlideDateTime - getDisplayValueInternal()
Returns the display value in the internal format, yyyy-MM-dd HH:mm:ss. This method is useful for date/time fields, but not for date fields.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | The date and time values for the GlideDateTime object. Format: yyyy-MM-dd HH:mm:ss in the caller's time zone. |
Example
Output:
Scoped equivalent
To use the getDisplayValueInternal() method in a scoped application, use the corresponding scoped method: getDisplayValueInternal().
GlideDateTime - getDisplayValueLang(String style)
Returns a date and time value in the current user's locale according to the specified date style.
Name | Type | Description |
---|---|---|
style | String | Specifies the date and time format. Valid values:
If any other value is passed the API will default to use medium. Accepted values are not case sensitive. |
Type | Description |
---|---|
String | A string representation of the date in the style specified and in the appropriate format for the locale of the current user. |
Example
The following example returns the date and time of the user's locale in all date styles.
Output:
GlideDateTime - getDisplayValueLang(String style, String language)
Returns a date and time value in the current user's locale according to a specified language and date style.
Name | Type | Description |
---|---|---|
style | String | Specifies the date and time format. Valid values:
If any other value is passed the API will default to use medium. Accepted values are not case sensitive. |
language | String | Returns the date according to a specified language value. Accepts language tags
that conform with the BCP-47 standard. For example, fr for French
or en-UK for British English. For a full list of accepted values,
see BCP 47 Language Code List. |
Type | Description |
---|---|
String | A string representation of the date in the style specified and in the appropriate format for the locale of the current user. |
Example
The following example returns the date and time of the user's locale in all language and date styles.
Output:
GlideDateTime - getDSTOffset()
Gets the amount of time that daylight saving time is offset.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | Amount of time, in milliseconds, that daylight saving is offset. Returns 0 if there is no offset or if the time is not during daylight saving time. |
Example
Output:
Scoped equivalent
To use the getDSTOffset() method in a scoped application, use the corresponding scoped method: getDSTOffset().
GlideDateTime - getErrorMsg()
Gets the current error message.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | The error message |
Example
Scoped equivalent
To use the getErrorMsg() method in a scoped application, use the corresponding scoped method: getErrorMsg().
GlideDateTime - getInternalFormattedLocalTime()
Returns the object's time in the local time zone and in the internal format.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | The object's time in the local time zone and the internal format. |
Example
This example displays the time in the system time format of the user's timezone.
Output:
Scoped equivalent
To use the getInternalFormattedLocalTime() method in a scoped application, use the corresponding scoped method: getInternalFormattedLocalTime().
GlideDateTime - getInternalMidnight(Number dayOfTheWeek)
Returns a date and time object set to midnight of a specified day using UTC.
Name | Type | Description |
---|---|---|
dayOfTheWeek | Number | The day of the week for which to return the date/time object. |
Type | Description |
---|---|
GlideDateTime | A GlideDateTime object set to midnight. |
Example
Output:
GlideDateTime - getLocalDate()
Gets the date stored by the GlideDateTime object, expressed in the standard format, yyyy-MM-dd, and the current user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideDate | The date in the user's time zone. |
Example
This example displays the time in the user's time format in the user's timezone.
Output:
Scoped equivalent
To use the getLocalDate() method in a scoped application, use the corresponding scoped method: getLocalDate().
GlideDateTime - getLocalTime()
Gets the time in the user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideTime | The time in the user's time zone. |
Example
Output:
Scoped equivalent
To use the getLocalTime() method in a scoped application, use the corresponding scoped method: getLocalTime().
GlideDateTime - getMonth()
Retrieves the month stored by the GlideDateTime object, expressed in Java Virtual Machine time zone.
Use getMonthLocalTime() and getMonthUTC() instead of this method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The numerical value of the month, Jan=1, Dec=12. |
Example
Output:
GlideDateTime - getMonthLocalTime()
Gets the month stored by the GlideDateTime object, expressed in the current user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The numerical value of the month, Jan=1, Dec=12. |
Example
Output:
Scoped equivalent
To use the getMonthLocalTime() method in a scoped application, use the corresponding scoped method: getMonthLocalTime().
GlideDateTime - getMonthUTC()
Gets the month stored by the GlideDateTime object, expressed in the UTC time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The numerical value of the month, Jan=1, Dec=12. |
Example
Output:
Scoped equivalent
To use the getMonthUTC() method in a scoped application, use the corresponding scoped method: getMonthUTC().
GlideDateTime - getNumericValue()
Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of milliseconds since January 1, 1970, 00:00:00 GMT. |
Example
Output:
GlideDateTime - getSpanTime(Number dayOfWeek)
Retrieves the amount of time elapsed since the midnight of a specified day to the current time.
Name | Type | Description |
---|---|---|
dayOfWeek | Number | Day of week value from 1 to 7. 1 = Monday, 7=Sunday. |
Type | Description |
---|---|
GlideTime | The amount of time elapsed since midnight of the specified day. To display the result in user-friendly terms, set the value to GlideDuration. |
Example
Output:
GlideDateTime - getTime()
Gets the Unix duration stamp.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
GlideTime | The Unix duration stamp in system format based on GMT time. |
Example
Output:
Scoped equivalent
To use the getTime() method in a scoped application, use the corresponding scoped method: getTime().
GlideDateTime - getTZOffset()
Gets the time zone offset in milliseconds.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of milliseconds of the time zone offset |
Example
Output:
Scoped equivalent
To use the getTZOffset() method in a scoped application, use the corresponding scoped method: getTZOffset().
GlideDateTime - getUserFormattedLocalTime()
Returns the object's time in local time zone in the user's format.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | The object's time in local time and the user's format. |
Example
The following code example shows how to call this method.
Output:
Scoped equivalent
To use the getUserFormattedLocalTime() method in a scoped application, use the corresponding scoped method: getUserFormattedLocalTime().
GlideDateTime - getUserTimeZone()
Retrieves the time zone for the current user session.
This method is equivalent to gs.getSession().getTimeZone()
.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
TimeZone | TimeZone object for the current user. |
Example
Output:
GlideDateTime - getUTCMidnight(Number dayOfTheWeek)
Retrieves a GlideDateTime object with the time set to midnight using the UTC time zone.
This method sets the date of the new GlideDateTime object as the specified day of the week within the week of the original GlideDateTime object.
Name | Type | Description |
---|---|---|
dayOfTheWeek | Number | The day of the week, from 1 to 7. Monday=1, Sunday=7. Do not enter 0 in this parameter. |
Type | Description |
---|---|
GlideDateTime | A new GlideDateTime object, set to midnight. |
Example
Output:
GlideDateTime - getValue()
Returns the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, in the UTC time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | Date and time in the internal format and system time zone. Format: yyyy-MM-dd HH:mm:ss in the UTC time zone. |
Example
Output:
Scoped equivalent
To use the getValue() method in a scoped application, use the corresponding scoped method: getValue().
GlideDateTime - getWeekOfYearLocalTime()
Gets the number of the week stored by the GlideDateTime object, expressed in the current user's time zone.
All weeks begin on Sunday. The first week of the year is the week that contains at least one day of the new year. The week beginning Sunday 2015-12-27 is considered the first week of 2016 as that week contains January 1 and 2.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of the current week. The highest week number in a year is either 52 or 53. |
Example
Output:
Scoped equivalent
To use the getWeekOfYearLocalTime() method in a scoped application, use the corresponding scoped method: getWeekOfYearLocalTime().
GlideDateTime - getWeekOfYearUTC()
Gets the number of the week stored by the GlideDateTime object, expressed in the UTC time zone.
All weeks begin on Sunday. The first week of the year is the week that contains at least one day of the new year. The week beginning Sunday 2015-12-27 is considered the first week of 2016 as that week contains January 1 and 2.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The number of the current week in UTC time. The highest week number in a year is either 52 or 53. |
Example
Output:
Scoped equivalent
To use the getWeekOfYearUTC() method in a scoped application, use the corresponding scoped method: getWeekOfYearUTC().
GlideDateTime - getYear()
Retrieves the year stored by the GlideDateTime object, expressed in the Java Virtual Machine time zone.
Use getYearLocalTime() and getYearUTC() instead of this method.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The 4-digit year value in the Java Virtual Machine time zone. |
Example
Output:
GlideDateTime - getYearLocalTime()
Gets the year stored by the GlideDateTime object, expressed in the current user's time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Number | The 4-digit year value in the user's time zone. |
Example
Output:
Scoped equivalent
To use the getYearLocalTime() method in a scoped application, use the corresponding scoped method: getYearLocalTime().
GlideDateTime - getYearUTC()
Returns the year stored by the GlideDateTime object, expressed in the UTC time zone.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
number | Four-digit year value in the UTC time zone. |
Example
Output:
Scoped equivalent
To use the getYearUTC() method in a scoped application, use the corresponding scoped method: getYearUTC().
GlideDateTime - hasDate()
Determines if an object's date is set.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the object's date is set, false otherwise. |
Example
Output:
Scoped equivalent
To use the hasDate() method in a scoped application, use the corresponding scoped method: hasDate().
GlideDateTime - isDST()
Determines if the object's time uses a daylight saving offset
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if the time is daylight saving time, false otherwise. |
Example
Output:
Scoped equivalent
To use the isDST() method in a scoped application, use the corresponding scoped method: isDST().
GlideDateTime - isValid()
Determines if a value is a valid date and time.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Boolean | True if value is valid, false otherwise. |
Example
Output
Scoped equivalent
To use the isValid() method in a scoped application, use the corresponding scoped method: isValid().
GlideDateTime - setDayOfMonth(Number day)
Sets the day of the month to a specified value.
Use setDayOfMonthLocalTime(day) and setDayOfMonthUTC(day) instead of this method.
Name | Type | Description |
---|---|---|
day | Number | Day of the month, from 1 to 31. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - setDayOfMonthLocalTime(Number day)
Sets the day of the month to a specified value in the current user's time zone.
Name | Type | Description |
---|---|---|
day | Number | The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setDayOfMonthLocalTime() method in a scoped application, use the corresponding scoped method: setDayOfMonthLocalTime().
GlideDateTime - setDayOfMonthUTC(Number day)
Sets the day of the month to a specified value in the UTC time zone.
Name | Type | Description |
---|---|---|
day | Number | The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setDayOfMonthUTC() method in a scoped application, use the corresponding scoped method: setDayOfMonthUTC().
GlideDateTime - setDisplayValue(String asDisplayed)
Sets a date and time value using the current user's display format and time zone.
Name | Type | Description |
---|---|---|
asDisplayed | String | The date and time in the current user's display format and time zone. The
parameter must be formatted using the current user's preferred display format, such
as MM-dd-yyyy HH:mm:ss. To assign the current date and time to a variable in a
workflow script, use
<variable>.setDisplayValue(gs.nowDateTime); . |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setDisplayValue() method in a scoped application, use the corresponding scoped method: setDisplayValue().
GlideDateTime - setDisplayValue(String dateTime, String format)
Sets a date and time value using the current user's time zone and the specified date and time format.
This method throws a runtime exception if the date and time format used in the dateTime parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught.
Name | Type | Description |
---|---|---|
dateTime | String | The date and time in the current user's time zone. |
format | String | The format to use to parse the dateTime parameter. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setDisplayValue() method in a scoped application, use the corresponding scoped method: setDisplayValue().
GlideDateTime - setDisplayValueInternal(String dateTime)
Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the current user's time zone.
Name | Type | Description |
---|---|---|
dateTime | String | The date and time in internal format |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setDisplayValueInternal() method in a scoped application, use the corresponding scoped method: setDisplayValueInternal().
GlideDateTime - setDisplayValueInternalWithAlternates(String dateTime)
Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the current user's time zone.
This method attempts to parse incomplete date and time values.
Name | Type | Description |
---|---|---|
dateTime | String | The date and time in internal format. |
Type | Description |
---|---|
void |
GlideDateTime - setDisplayValueLang(String dateTime, String style)
Sets a date using a specified style and format according to the current user's locale.
Name | Type | Description |
---|---|---|
dateTime | String | Date and time value for the GlideDate object in the current user's time zone.
Valid values are any date and time output from the
getDisplayValueLang() function. For instance, using output from the getDisplayValueLang(String style, String language) example earlier in this topic, November 28, 2022 07:03:41 or 28.11.2022 07:03:41 are accepted values. |
style | String | Specifies the date format. Valid values:
If any other value is passed the API will default to use medium. Accepted values are not case sensitive. |
Type | Description |
---|---|
Void |
Example
The following example returns the date and time in short and full styles.
Output:
GlideDateTime - setDisplayValueLang(String dateTime, String style, String language)
Sets a date and time using a specified style, language, and format according to the current user's locale.
Name | Type | Description |
---|---|---|
dateTime | String | Date and time value for the GlideDate object in the current user's time zone.
Valid values are any date and time output from the
getDisplayValueLang() function. For instance, using output from the getDisplayValueLang(String style, String language) example earlier in this topic, November 28, 2022 07:03:41 or 28.11.2022 07:03:41 are accepted values. |
style | String | Specifies the date format. Valid values:
If any other value is passed the API will default to use medium. Accepted values are not case sensitive. |
language | String | Sets the language using a language tag that conforms with the BCP-47 standard.
For example, fr for French or en-UK for British
English. For a full list of accepted values, see BCP 47 Language Code List. |
Type | Description |
---|---|
Void |
Example
The following example returns the date and time in short and full styles for English and French.
Output:
GlideDateTime - setGlideDateTime(GlideDateTime gDT)
Sets the date and time of the current object using an existing GlideDateTime object.
This method is equivalent to instantiating a new object with a GlideDateTime parameter.
Name | Type | Description |
---|---|---|
gDT | GlideDateTime | A GlideDateTime object |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setGlideDateTime() method in a scoped application, use the corresponding scoped method: setGlideDateTime().
GlideDateTime - setInitialValue(String dateTime)
Sets the date and time.
This method is equivalent to setValue(Object).
Name | Type | Description |
---|---|---|
dateTime | String | The date and time to use. Accepts either a string in the GMT time zone in the internal format, or a GlideDateTime object. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - setMonth(Number month)
Sets the month stored by the GlideDateTime object to a specified value using the Java Virtual Machine time zone.
Use setMonthLocalTime() or setMonthUTC() instead of this method.
Name | Type | Description |
---|---|---|
month | Number | The month to change to. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - setMonthLocalTime(Number month)
Sets the month stored by the GlideDateTime object to a specified value using the current user's time zone.
Name | Type | Description |
---|---|---|
month | Number | The month to change to. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setMonthLocalTime() method in a scoped application, use the corresponding scoped method: setMonthLocalTime().
GlideDateTime - setMonthUTC(Number month)
Sets the month stored by the GlideDateTime object to a specified value using the UTC time zone.
Name | Type | Description |
---|---|---|
month | Number | The month to change to. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setMonthUTC() method in a scoped application, use the corresponding scoped method: setMonthUTC().
GlideDateTime - setNumericValue(Number milliseconds)
Sets the date and time to the number of milliseconds since January 1, 1970 00:00:00 GMT.
Name | Type | Description |
---|---|---|
milliseconds | Number | Number of milliseconds |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - setTZ(TimeZone timeZone)
Sets the time zone of the GlideDateTime object to be the specified time zone.
Name | Type | Description |
---|---|---|
timeZone | TimeZone | A time zone object |
Type | Description |
---|---|
void |
Example
GlideDateTime - setValue(Object dateTime)
Sets the date and time of the GlideDateTime object.
This method is equivalent to setInitialValue().
Name | Type | Description |
---|---|---|
dateTime | Object | The date and time to use. This parameter may be one of several types.
|
Type | Description |
---|---|
void |
Example
Set the date and time using a string in yyyy-MM-dd HH:mm:ss format.
Output:
Example
Set the date and time using an existing GlideDateTime object.
Output:
Example
Set the date and time using a number indicating milliseconds past January 1, 1970 00:00:00 UTC.
Output:
Scoped equivalent
To use the setValue() method in a scoped application, use the corresponding scoped method: setValue().
GlideDateTime - setValueUTC(String dateTime, String format)
Sets a date and time value using the UTC time zone and the specified date and time format.
This method throws a runtime exception if the date and time format used in the dateTime parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught.
Name | Type | Description |
---|---|---|
dateTime | String | The date and time to use. |
format | String | The format to use. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setValueUTC() method in a scoped application, use the corresponding scoped method: setValueUTC().
GlideDateTime - setYear(Number year)
Sets the year stored by the GlideDateTime object to a specified value using the Java Virtual Machine time zone.
Use setYearLocalTime() or setYearUTC() instead of this method.
Name | Type | Description |
---|---|---|
year | Number | The year to change to. |
Type | Description |
---|---|
void |
Example
Output:
GlideDateTime - setYearLocalTime(Number year)
Sets the year stored by the GlideDateTime object to a specified value using the current user's time zone.
Name | Type | Description |
---|---|---|
year | Number | The year to change to. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setYearLocalTime() method in a scoped application, use the corresponding scoped method: setYearLocalTime().
GlideDateTime - setYearUTC(Number year)
Sets the year stored by the GlideDateTime object to a specified value using the UTC time zone.
Name | Type | Description |
---|---|---|
year | Number | The year to change to. |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the setYearUTC() method in a scoped application, use the corresponding scoped method: setYearUTC().
GlideDateTime - subtract(GlideTime time)
Subtracts a specified amount of time.
Name | Type | Description |
---|---|---|
time | GlideTime | The time to subtract |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the subtract() method in a scoped application, use the corresponding scoped method: subtract().
GlideDateTime - subtract(Number milliseconds)
Subtracts a specified number of milliseconds from the GlideDateTime object.
Name | Type | Description |
---|---|---|
milliseconds | Number | The number of milliseconds to subtract |
Type | Description |
---|---|
void |
Example
Output:
Scoped equivalent
To use the subtract() method in a scoped application, use the corresponding scoped method: subtract().
GlideDateTime - subtract(GlideDateTime start, GlideDateTime end)
Returns the duration difference between two specified GlideDateTime objects.
Name | Type | Description |
---|---|---|
start | GlideDateTime | Start date object. |
end | GlideDateTime | End date object. |
Type | Description |
---|---|
GlideDuration | Duration difference between the two specified dates. |
Example
Output:
Scoped equivalent
To use the subtract() method in a scoped application, use the corresponding scoped method: subtract().
GlideDateTime - toString()
Returns the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default.
This method is equivalent to getValue().
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
Object | The date and time stored by the GlideDateTime object in the system time zone and format. |
Example
Output:
Scoped equivalent
To use the toString() method in a scoped application, use the corresponding scoped method: toString().