GlideTime - Scoped

The scoped GlideTime class provides methods for performing operations on GlideTime objects, such as instantiating GlideTime objects or working with GlideTime fields.

Scoped GlideTime - getByFormat(String format)

Gets the time in the specified format.

Table 1. Parameters
Name Type Description
format String The time format.
Table 2. Returns
Type Description
String The time in the specified format.
var gt = new GlideTime(); 
gt.setValue('12:00:00');
gs.info(gt.getByFormat("HH:mm"));

Output:

Scoped GlideTime - getDisplayValue()

Gets the time in the current user's display format and time zone.

When designing business rules or script includes remember that this method may return values in different formats for different users.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String The time in the user's format and time zone.
var gt = new GlideTime();
gt.setDisplayValue("12:00:00"); // User Time Zone
gs.info(gt.getDisplayValue()); // User Time Zone

Output:

Scoped GlideTime - getDisplayValueInternal()

Gets the display value in the current user's time zone and the internal format (HH:mm:ss).

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String The time value for the GlideTime object in the current user's time zone and the internal time format of HH:mm:ss.
var gt = new GlideTime();
gt.setValue("01:00:00"); //Internal Time Zone , UTC
gs.info(gt.getDisplayValueInternal()); //User Time Zone

Output:

Scoped GlideTime - getHourLocalTime()

Returns the hours part of the time using the local time zone.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
Number The hours using the local time zone.

Scoped GlideTime - getHourOfDayUTC()

Returns the hours part of the time using the UTC time zone. The number of hours is based on a 24 hour clock.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
Number The hours using the UTC time zone. The number of hours is based on a 24 hour clock.

Scoped GlideTime - getHourOfDayLocalTime()

Returns the hours part of the time using the local time zone. The number of hours is based on a 24 hour clock.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
Number The hours using the local time zone. The number of hours is based on a 24 hour clock.

Scoped GlideTime - getHourUTC()

Returns the hours part of the time using the UTC time zone. The number of hours is based on a 12 hour clock. Noon and midnight are represented by 0, not 12.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
Number The hours using the UTC time zone. The number of hours is based on a 12 hour clock. Noon and midnight are represented by 0, not 12.

Scoped GlideTime - getMinutesLocalTime()

Returns the number of minutes using the local time zone.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
Number The number of minutes using the local time zone.

Scoped GlideTime - getMinutesUTC()

Returns the number of minutes in the hour based on the UTC time zone.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
Number The number of minutes in the hour using the UTC time zone.

Scoped GlideTime - getSeconds()

Returns the number of seconds in the current minute.

Table 19. Parameters
Name Type Description
None
Table 20. Returns
Type Description
Number The number of seconds in the minute.

Scoped GlideTime - getValue()

Gets the time value stored in the database by the GlideTime object in the internal format, HH:mm:ss, and the system time zone.

Table 21. Parameters
Name Type Description
None
Table 22. Returns
Type Description
String The time value in the internal fomat and system time zone.
var gt = new GlideTime();
gs.info(gt.getValue()); // Internal Time Zone, UTC

Output:

Scoped GlideTime - GlideTime()

Instantiates a GlideTime object with the current time.

Table 23. Parameters
Name Type Description
None
var gt = new GlideTime(); 
gs.info(gt.getDisplayValue());

Output:

Scoped GlideTime - GlideTime(Number milliseconds)

Instantiates a GlideTime object with the specified time.

Table 24. Parameters
Name Type Description
milliseconds Number The datetime in milliseconds.
var gt = new GlideTime(10000); 
gs.info(gt.getDisplayValue());

Output:

Scoped GlideTime - setDisplayValue(String asDisplayed)

Sets a time value using the current user's display format and time zone.

Table 25. Parameters
Name Type Description
asDisplayed String The 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 HH:mm:ss.
Table 26. Returns
Type Description
void
var gt = new GlideTime();
gt.setDisplayValue('01:00:00');   // User Time Zone
gs.info(gt.getDisplayValueInternal()); // User Time Zone

Output:

Scoped GlideTime - setValue(String o)

Sets the time of the GlideTime object in the internal time zone.

Table 27. Parameters
Name Type Description
o String The time in hh:mm:ss format.
Table 28. Returns
Type Description
void
var gt = new GlideTime();
gt.setValue('01:00:00');  //Internal Time Zone, UTC
gs.info("time is "+ gt.getByFormat('hh:mm:ss'));

Output:

Scoped GlideTime - subtract(GlideTime startTime, GlideTime endTime)

Gets the duration difference between two GlideTime object values.

Table 29. Parameters
Name Type Description
startTime GlideTime The start value.
endTime GlideTime The end value.
Table 30. Returns
Type Description
GlideDuration The duration between the two values.
var gd1 = new GlideTime(); 
gd1.setDisplayValue("09:00:00"); 
var gd2 = new GlideTime(); 
gd2.setDisplayValue("09:10:00"); 
 
var dur = GlideDate.subtract(gd1, gd2); //the difference between gdt1 and gdt2 
gs.info(dur.getDisplayValue());

Output: