{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1040,"path":"api-reference/server-api-reference/c_GlideTimeScopedAPI.md","title":"GlideTime - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideTime- Scoped\n\nThe GlideTime API provides methods for performing operations on GlideTime objects, such as instantiating GlideTime objects or working with GlideTime fields.\n\nFor guidance on date time input strings with a list of common format conflicts, refer to [Date and time format guidelines](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/p_GlideServerAPIs.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideTime - GlideTime\\(\\)\n\nInstantiates a GlideTime object with the current time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n```\nvar gt = new GlideTime(); \ngs.info(gt.getDisplayValue());\n```\n\n## GlideTime - GlideTime\\(Number milliseconds\\)\n\nInstantiates a GlideTime object with its time starting at midnight UTC plus the passed in value.\n\nThe 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.\\)\n\n<table id=\"table_vy2_525_jq\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nmilliseconds\n\n</td><td>\n\nNumber\n\n</td><td>\n\nTime to add to midnight UTC.Unit: Milliseconds\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar gt = new GlideTime(10000); \ngs.info(gt.getDisplayValue());\n```\n\nOutput:\n\n```\n16:00:10\n```\n\n## GlideTime - getByFormat\\(String format\\)\n\nReturns the time in the specified format.\n\nFor information on the time formats that you can pass into this method, see [Global date and time field format](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-administration/r_FormatDateAndTimeFields.md). 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.\n\n<table id=\"table_vy2_525_jq\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nformat\n\n</td><td>\n\nString\n\n</td><td>\n\nString to use to format the time.For example, if the current time is 10:30:20 then:\n\n-   hh:mm:ss = 10:30:20\n-   HH = 10\n-   HH –- ss = 10 –- 20\n-   hh a = 10 AM\n-   s:m:H ss:mm:hh = 20:30:10 20:30:10\n-   HH/mm/ss = 10/30/20\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Time in the specified format.|\n\n```\nvar gt = new GlideTime(); \ngt.setValue('12:00:00');\ngs.info(gt.getByFormat(\"HH:mm\"));\n```\n\nOutput:\n\n```\n12:00\n```\n\n## GlideTime - getDisplayValue\\(\\)\n\nGets the time in the current user's display format and time zone.\n\nWhen designing business rules or script includes remember that this method may return values in different formats for different users.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The time in the user's format and time zone.|\n\n```\nvar gt = new GlideTime();\ngt.setDisplayValue(\"12:00:00\"); // User Time Zone\ngs.info(gt.getDisplayValue()); // User Time Zone\n```\n\n## GlideTime - getDisplayValueEx\\(String style\\)\n\nReturns the time using the current user's timezone and a specified format.\n\n<table id=\"table_tg4_ckc_b3c\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nFormat to use for the time.Valid values \\(case insensitive\\):\n\n-   `short`: HH:mm \\(AM/PM\\)\n-   `medium`: HH:mm:ss \\(AM/PM\\)\n-   `long`: HH:mm:ss \\(AM/PM\\) timezone abbreviation\n-   `full`: HH:mm:ss \\(AM/PM\\) timezone\n\nThe time is returned in the current user's language. The language determines whether the time is returned in 12 hour or 24 hour format.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|The time in the specified format.|\n\nThis example returns the time using the current user's timezone and each formatting option.\n\n```\nvar gt = new GlideTime();\ngs.info(gt.getDisplayValueEx(\"short\"));\ngs.info(gt.getDisplayValueEx(\"medium\"));\ngs.info(gt.getDisplayValueEx(\"long\"));\ngs.info(gt.getDisplayValueEx(\"full\"));\n```\n\nOutput:\n\n```\n8:52 AM  //short\n8:52:24 AM  //medium\n8:52:24 AM PST  //long\n8:52:24 AM Pacific Standard Time  //full\n```\n\n## GlideTime - getDisplayValueInternal\\(\\)\n\nGets the display value in the current user's time zone and the internal format \\(HH:mm:ss\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The time value for the GlideTime object in the current user's time zone and the internal time format of HH:mm:ss.|\n\n```\nvar gt = new GlideTime();\ngt.setValue(\"01:00:00\"); //Internal Time Zone , UTC\ngs.info(gt.getDisplayValueInternal()); //User Time Zone\n```\n\n## GlideTime - getDisplayValueLang\\(String style, String language\\)\n\nReturns the time using the current user's timezone and a specified format and language.\n\n<table id=\"table_ygv_fkc_b3c\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nFormat to use for the time.Valid values \\(case insensitive\\):\n\n-   `short`: HH:mm \\(AM/PM\\)\n-   `medium`: HH:mm:ss \\(AM/PM\\)\n-   `long`: HH:mm:ss \\(AM/PM\\) timezone abbreviation\n-   `full`: HH:mm:ss \\(AM/PM\\) timezone\n\n</td></tr><tr><td>\n\nlanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Language to return the time in, provided as a BCP 47 language tag. For example, to return the time in Japanese use the tag `ja`.The language determines whether the time is returned in 12 hour or 24 hour format. For example, times in English use the 12 hour format, while times in Japanese use the 24 hour format.\n\nDefault: Current user's language.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|The time in the specified format and language.|\n\nThis example returns the time in Spanish using the current user's timezone and each formatting option.\n\n```\nvar gt = new GlideTime();\ngs.info(gt.getDisplayValueLang(\"short\", \"es\"));\ngs.info(gt.getDisplayValueLang(\"medium\", \"es\"));\ngs.info(gt.getDisplayValueLang(\"long\", \"es\"));\ngs.info(gt.getDisplayValueLang(\"full\", \"es\"));\n```\n\nOutput:\n\n```\n9:25  //short\n9:25:44  //medium\n9:25:44 PST  //long\n9:25:44 (hora estándar del Pacífico)  //full\n```\n\n## GlideTime - getHourLocalTime\\(\\)\n\nReturns the hours part of the time using the local time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The hours using the local time zone.|\n\n## GlideTime - getHourOfDayLocalTime\\(\\)\n\nReturns the hours part of the time using the local time zone. The number of hours is based on a 24 hour clock.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The hours using the local time zone. The number of hours is based on a 24 hour clock.|\n\n## GlideTime - getHourOfDayUTC\\(\\)\n\nReturns the hours part of the time using the UTC time zone. The number of hours is based on a 24 hour clock.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The hours using the UTC time zone. The number of hours is based on a 24 hour clock.|\n\n## GlideTime - getHourUTC\\(\\)\n\nReturns 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n## GlideTime - getMinutesLocalTime\\(\\)\n\nReturns the number of minutes using the local time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of minutes using the local time zone.|\n\n## GlideTime - getMinutesUTC\\(\\)\n\nReturns the number of minutes in the hour based on the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of minutes in the hour using the UTC time zone.|\n\n## GlideTime - getSeconds\\(\\)\n\nReturns the number of seconds in the current minute.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of seconds in the minute.|\n\n## GlideTime - getValue\\(\\)\n\nGets the time value stored in the database by the GlideTime object in the internal format, HH:mm:ss, and the system time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The time value in the internal fomat and system time zone.|\n\n```\nvar gt = new GlideTime();\ngs.info(gt.getValue()); // Internal Time Zone, UTC\n```\n\n## GlideTime - setDisplayValue\\(String asDisplayed\\)\n\nSets a time value using the current user's display format and time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gt = new GlideTime();\ngt.setDisplayValue('01:00:00');   // User Time Zone\ngs.info(gt.getDisplayValueInternal()); // User Time Zone\n```\n\n## GlideTime - setDisplayValueEx\\(String time, String style\\)\n\nSets the time using the current user's timezone and a specified format.\n\n<table id=\"table_zb5_3kc_b3c\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntime\n\n</td><td>\n\nString\n\n</td><td>\n\nValue to set for the time. The [getDisplayValueEx\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideTimeScopedAPI.md) method returns times in a valid format, or times can be formatted as shown below.\n\n-   HH:mm \\(AM/PM\\)\n-   HH:mm:ss \\(AM/PM\\)\n-   HH:mm:ss \\(AM/PM\\) timezone abbreviation\n-   HH:mm:ss \\(AM/PM\\) timezone\n\nThe current user's language determines whether 12 hour \\(AM/PM\\) or 24 hour time values are accepted. For example, if the current user's language is English `6:25 PM PST` is a valid value while `18:25 PST` is not.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nFormat to use for the time.You must use the same format as the provided **time** value.\n\nValid values \\(case insensitive\\):\n\n-   `short`: HH:mm \\(AM/PM\\)\n-   `medium`: HH:mm:ss \\(AM/PM\\)\n-   `long`: HH:mm:ss \\(AM/PM\\) timezone abbreviation\n-   `full`: HH:mm:ss \\(AM/PM\\) timezone\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example sets the time using the current user's timezone and a specified format.\n\n```\ngt = new GlideTime();\ngt.setDisplayValueEx(\"8:25:25 AM\", \"medium\");\ngs.info(gt.getDisplayValueEx(\"full\"));\n```\n\nOutput:\n\n```\n8:25:25 AM Pacific Standard Time\n```\n\n## GlideTime - setDisplayValueLang\\(String time, String style, String language\\)\n\nSets the time using the current user's timezone and a specified format and language.\n\n<table id=\"table_zb5_3kc_b3c\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntime\n\n</td><td>\n\nString\n\n</td><td>\n\nValue to set for the time. The [getDisplayValueLang\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideTimeScopedAPI.md) and [getDisplayValueEx\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideTimeScopedAPI.md) methods return times in a valid format, or times can be formatted as shown below.\n\n-   HH:mm \\(AM/PM\\)\n-   HH:mm:ss \\(AM/PM\\)\n-   HH:mm:ss \\(AM/PM\\) timezone abbreviation\n-   HH:mm:ss \\(AM/PM\\) timezone\n\nThe **language** parameter determines whether 12 hour \\(AM/PM\\) or 24 hour time values are accepted. For example, if the language is `en` \\(English\\), `6:25 PM PST` is a valid value while `18:25 PST` is not.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nFormat to use for the time.You must use the same format as the provided **time** value.\n\nValid values \\(case insensitive\\):\n\n-   `short`: HH:mm \\(AM/PM\\)\n-   `medium`: HH:mm:ss \\(AM/PM\\)\n-   `long`: HH:mm:ss \\(AM/PM\\) timezone abbreviation\n-   `full`: HH:mm:ss \\(AM/PM\\) timezone\n\n</td></tr><tr><td>\n\nlanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nLanguage to set the time in, provided as a BCP 47 language tag. For example, to set the time in Japanese, use the tag `ja`.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example sets the time in English using the current user's timezone and retrieves it in Spanish.\n\n```\ngt = new GlideTime();\ngt.setDisplayValueLang(\"4:15:00 PM PST\", \"long\", \"en\");\ngs.info(gt.getDisplayValueLang(\"full\", \"es\"));\n```\n\nOutput:\n\n```\n16:15:00 (hora estándar del Pacífico)\n```\n\n## GlideTime - setValue\\(String o\\)\n\nSets the time of the GlideTime object in the internal time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|o|String|The time in hh:mm:ss format.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gt = new GlideTime();\ngt.setValue('01:00:00');  //Internal Time Zone, UTC\ngs.info(\"time is \"+ gt.getByFormat('hh:mm:ss'));\n```\n\n## GlideTime - subtract\\(GlideTime startTime, GlideTime endTime\\)\n\nGets the duration difference between two GlideTime object values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|startTime|GlideTime|The start value.|\n|endTime|GlideTime|The end value.|\n\n|Type|Description|\n|----|-----------|\n|GlideDuration|The duration between the two values.|\n\n```\nvar gd1 = new GlideTime(); \ngd1.setDisplayValue(\"09:00:00\"); \nvar gd2 = new GlideTime(); \ngd2.setDisplayValue(\"09:10:00\"); \n \nvar dur = GlideDate.subtract(gd1, gd2); //the difference between gdt1 and gdt2 \ngs.info(dur.getDisplayValue());\n```\n\n"}}