---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideTime - Scoped

# GlideTime - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read

The GlideTime API provides methods for performing operations on GlideTime objects, such as instantiating GlideTime objects or working with GlideTime fields.
For guidance on date time input strings with a list of common format conflicts, refer to [Date and time format guidelines](https://servicenow-prod.fluidtopics.net/RgXT711o4n9v_sJ0uKmMsA#date-and-time-format-guidelines "You can specify a date format with a sequence of specific date and time pattern strings. A pattern string consists of one or more uppercase and lowercase letters from A to Z. Any text within quotation marks is ignored and is instead copied into the date output.").

## GlideTime - GlideTime() {#ariaid-title2}

Instantiates a GlideTime object with the current time.
{#r_ScopedGlideTimeGlideTime__table_cxr_tsb_2r__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#r_ScopedGlideTimeGlideTime__table_cxr_tsb_2r}  

    var gt = new GlideTime(); 
    gs.info(gt.getDisplayValue());

## GlideTime - GlideTime(Number milliseconds) {#ariaid-title3}

Instantiates a GlideTime object with its time starting at midnight UTC plus the passed
in value.
The value is adjusted for the timezone in which the instance resides. For example, if the
user's instance is in a time zone that is -8 hours from the UTC, and 1000 is passed in, the
time in the GlideTime object is 16:00:10 (00:00:00 - 8 hours +10 seconds.)
{#r_ScopedGlideTimeGlideTime_Number__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| milliseconds | Number | Time to add to midnight UTC. Unit: Milliseconds |
[Table 2. Parameters]

{#r_ScopedGlideTimeGlideTime_Number__table_vy2_525_jq}  
This example shows adding 10 seconds to midnight (UTC), which is then adjusted for the time
zone in which the instance resides. In this case, -8 hours from UTC.

    var gt = new GlideTime(10000); 
    gs.info(gt.getDisplayValue());

Output:

    16:00:10

## GlideTime - getByFormat(String format) {#ariaid-title4}

Returns the time in the specified format.
For information on the time formats that you can pass into this method, see [Global date and time field
format](https://www.servicenow.com/docs/access?context=r_FormatDateAndTimeFields&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US). You can pass these values in any order and add separators such as a dash,
space, backslash, or colon. In addition, you can also pass the character "a" to return
am/pm.
{#r_ScopedGlideTimeGetByFormat_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| format | String | String to use to format the time. For example, if the current time is 10:30:20 then: * hh:mm:ss = 10:30:20 * HH = 10 * HH --- ss = 10 --- 20 * hh a = 10 AM * s:m:H ss:mm:hh = 20:30:10 20:30:10 * HH/mm/ss = 10/30/20 {#r_ScopedGlideTimeGetByFormat_String__ul_cdw_4zy_jkb} |
[Table 3. Parameters]

{#r_ScopedGlideTimeGetByFormat_String__table_vy2_525_jq} {#r_ScopedGlideTimeGetByFormat_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Time in the specified format. |
[Table 4. Returns]

{#r_ScopedGlideTimeGetByFormat_String__table_qpt_3f5_jq}  

    var gt = new GlideTime(); 
    gt.setValue('12:00:00');
    gs.info(gt.getByFormat("HH:mm"));

Output:

    12:00

## GlideTime - getDisplayValue() {#ariaid-title5}

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.
{#r_ScopedGlideTimeGetDisplayValue__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#r_ScopedGlideTimeGetDisplayValue__table_vy2_525_jq} {#r_ScopedGlideTimeGetDisplayValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The time in the user's format and time zone. |
[Table 6. Returns]

{#r_ScopedGlideTimeGetDisplayValue__table_qpt_3f5_jq}  

    var gt = new GlideTime();
    gt.setDisplayValue("12:00:00"); // User Time Zone
    gs.info(gt.getDisplayValue()); // User Time Zone

## GlideTime - getDisplayValueInternal() {#ariaid-title6}

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

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#r_ScopedGlideTimeGetDisplayValueInternal__table_vy2_525_jq} {#r_ScopedGlideTimeGetDisplayValueInternal__table_qpt_3f5_jq__entry__2}

| 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. |
[Table 8. Returns]

{#r_ScopedGlideTimeGetDisplayValueInternal__table_qpt_3f5_jq}  

    var gt = new GlideTime();
    gt.setValue("01:00:00"); //Internal Time Zone , UTC
    gs.info(gt.getDisplayValueInternal()); //User Time Zone

## GlideTime - getHourLocalTime() {#ariaid-title7}

Returns the hours part of the time using the local time zone.
{#r_SGT-getHourLocalTime__table_pwr_c2d_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#r_SGT-getHourLocalTime__table_pwr_c2d_kw} {#r_SGT-getHourLocalTime__table_qwr_c2d_kw__entry__2}

| Type | Description |
|-|-|
| Number | The hours using the local time zone. |
[Table 10. Returns]

{#r_SGT-getHourLocalTime__table_qwr_c2d_kw}

## GlideTime - getHourOfDayLocalTime() {#ariaid-title8}

Returns the hours part of the time using the local time zone. The number of hours is
based on a 24 hour clock.
{#r_SGT-getHourOfDayLocalTime__table_lrw_4dd_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#r_SGT-getHourOfDayLocalTime__table_lrw_4dd_kw} {#r_SGT-getHourOfDayLocalTime__table_mrw_4dd_kw__entry__2}

| Type | Description |
|-|-|
| Number | The hours using the local time zone. The number of hours is based on a 24 hour clock. |
[Table 12. Returns]

{#r_SGT-getHourOfDayLocalTime__table_mrw_4dd_kw}

## GlideTime - getHourOfDayUTC() {#ariaid-title9}

Returns the hours part of the time using the UTC time zone. The number of hours is
based on a 24 hour clock.
{#r_SGT-getHourOfDayUTC__table_bv5_zxc_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#r_SGT-getHourOfDayUTC__table_bv5_zxc_kw} {#r_SGT-getHourOfDayUTC__table_cv5_zxc_kw__entry__2}

| Type | Description |
|-|-|
| Number | The hours using the UTC time zone. The number of hours is based on a 24 hour clock. |
[Table 14. Returns]

{#r_SGT-getHourOfDayUTC__table_cv5_zxc_kw}

## GlideTime - getHourUTC() {#ariaid-title10}

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.
{#r_SGT-getHourUTC__table_cfh_nyc_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 15. Parameters]

{#r_SGT-getHourUTC__table_cfh_nyc_kw} {#r_SGT-getHourUTC__table_dfh_nyc_kw__entry__2}

| 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. |
[Table 16. Returns]

{#r_SGT-getHourUTC__table_dfh_nyc_kw}

## GlideTime - getMinutesLocalTime() {#ariaid-title11}

Returns the number of minutes using the local time zone.
{#r_SGT-getMinutesLocalTime__table_gx3_q2d_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 17. Parameters]

{#r_SGT-getMinutesLocalTime__table_gx3_q2d_kw} {#r_SGT-getMinutesLocalTime__table_hx3_q2d_kw__entry__2}

| Type | Description |
|-|-|
| Number | The number of minutes using the local time zone. |
[Table 18. Returns]

{#r_SGT-getMinutesLocalTime__table_hx3_q2d_kw}

## GlideTime - getMinutesUTC() {#ariaid-title12}

Returns the number of minutes in the hour based on the UTC time zone.
{#r_SGT-getMinutesUTC__table_qvr_xcd_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 19. Parameters]

{#r_SGT-getMinutesUTC__table_qvr_xcd_kw} {#r_SGT-getMinutesUTC__table_rvr_xcd_kw__entry__2}

| Type | Description |
|-|-|
| Number | The number of minutes in the hour using the UTC time zone. |
[Table 20. Returns]

{#r_SGT-getMinutesUTC__table_rvr_xcd_kw}

## GlideTime - getSeconds() {#ariaid-title13}

Returns the number of seconds in the current minute.
{#r_SGT-getSeconds__table_dkh_1fd_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 21. Parameters]

{#r_SGT-getSeconds__table_dkh_1fd_kw} {#r_SGT-getSeconds__table_ekh_1fd_kw__entry__2}

| Type | Description |
|-|-|
| Number | The number of seconds in the minute. |
[Table 22. Returns]

{#r_SGT-getSeconds__table_ekh_1fd_kw}

## GlideTime - getValue() {#ariaid-title14}

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

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 23. Parameters]

{#r_ScopedGlideTimeGetValue__table_vy2_525_jq} {#r_ScopedGlideTimeGetValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The time value in the internal fomat and system time zone. |
[Table 24. Returns]

{#r_ScopedGlideTimeGetValue__table_qpt_3f5_jq}  

    var gt = new GlideTime();
    gs.info(gt.getValue()); // Internal Time Zone, UTC

## GlideTime - setDisplayValue(String asDisplayed) {#ariaid-title15}

Sets a time value using the current user's display format and time zone.
{#r_ScopedGlideTimeSetDisplayValue_String__table_vy2_525_jq__entry__3}

| 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 25. Parameters]

{#r_ScopedGlideTimeSetDisplayValue_String__table_vy2_525_jq} {#r_ScopedGlideTimeSetDisplayValue_String__table_qpt_3f5_jq1__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 26. Returns]

{#r_ScopedGlideTimeSetDisplayValue_String__table_qpt_3f5_jq1}  

    var gt = new GlideTime();
    gt.setDisplayValue('01:00:00');   // User Time Zone
    gs.info(gt.getDisplayValueInternal()); // User Time Zone

## GlideTime - setValue(String o) {#ariaid-title16}

Sets the time of the GlideTime object in the internal time zone.
{#r_ScopedGlideTimeSetValue_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| o | String | The time in hh:mm:ss format. |
[Table 27. Parameters]

{#r_ScopedGlideTimeSetValue_String__table_vy2_525_jq} {#r_ScopedGlideTimeSetValue_String__table_qpt_3f5_jq1__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 28. Returns]

{#r_ScopedGlideTimeSetValue_String__table_qpt_3f5_jq1}  

    var gt = new GlideTime();
    gt.setValue('01:00:00');  //Internal Time Zone, UTC
    gs.info("time is "+ gt.getByFormat('hh:mm:ss'));

## GlideTime - subtract(GlideTime startTime, GlideTime endTime) {#ariaid-title17}

Gets the duration difference between two GlideTime object values.
{#r_ScopedGlideTimeSubtract_GlideTime_GlideTime__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| startTime | GlideTime | The start value. |
| endTime | GlideTime | The end value. |
[Table 29. Parameters]

{#r_ScopedGlideTimeSubtract_GlideTime_GlideTime__table_vy2_525_jq} {#r_ScopedGlideTimeSubtract_GlideTime_GlideTime__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideDuration | The duration between the two values. |
[Table 30. Returns]

{#r_ScopedGlideTimeSubtract_GlideTime_GlideTime__table_qpt_3f5_jq}  

    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());


