Calendar
The Calendar class contains properties, and functions for manipulating JavaScript date objects. This class supported by OmniGraffle, OmniFocus, OmniOutliner, and OmniPlan.
Class Properties
buddhist (Calendar r/o) • The Buddhist calendar is a set of lunisolar calendars primarily used in mainland Southeast Asian countries of Cambodia, Laos, Myanmar and Thailand as well as in Sri Lanka and Chinese populations of Malaysia and Singapore for religious or official occasions. (Wikipedia)
chinese (Calendar r/o) • The traditional Chinese calendar is a lunisolar calendar which reckons years, months and days according to astronomical phenomena. It was developed by the Qin Dynasty. As of 2017, the Chinese calendar is defined by GB/T 33661-2017 Calculation and promulgation of the Chinese calendar, which the Standardization Administration of China issued on May 12, 2017. (Wikipedia)
coptic (Calendar r/o) • The Coptic calendar, also called the Alexandrian calendar, is a liturgical calendar used by the Coptic Orthodox Church and still used in Egypt. This calendar is based on the ancient Egyptian calendar. (Wikipedia)
current (Calendar r/o) • The user’s preferred calendar.
ethiopicAmeteAlem (Calendar r/o) • The Ethiopic (Amete Alem) calendar is a solar calendar which in turn derives from the Egyptian Calendar, but like the Julian Calendar, it adds a leap day every four years without exception, and begins the year on August 29 or August 30 in the Julian Calendar. (Wikipedia)
ethiopicAmeteMihret (Calendar r/o) • The Ethiopic (Amete Mihret) calendar is a solar calendar which in turn derives from the Egyptian Calendar, but like the Julian Calendar, it adds a leap day every four years without exception, and begins the year on August 29 or August 30 in the Julian Calendar. (Wikipedia)
gregorian (Calendar r/o) • The Gregorian calendar is internationally the most widely used civil calendar.[1][2][Note 1] It is named after Pope Gregory XIII, who introduced it in October 1582. (Wikipedia)
hebrew (Calendar r/o) • The Hebrew or Jewish calendar is a lunisolar calendar used today predominantly for Jewish religious observances. (Wikipedia)
indian (Calendar r/o) • The Indian national calendar, sometimes called the Shalivahana Shaka calendar. It is used, alongside the Gregorian calendar, by The Gazette of India, in news broadcasts by All India Radio and in calendars and communications issued by the Government of India. (Wikipedia)
islamic (Calendar r/o) • The Islamic, Muslim, or Hijri calendar is a lunar calendar consisting of 12 months in a year of 354 or 355 days. It is used (often alongside the Gregorian calendar) to date events in many Muslim countries. It is also used by Muslims to determine the proper days of Islamic holidays and rituals, such as the annual period of fasting and the proper time for the pilgrimage to Mecca. (Wikipedia)
islamicCivil (Calendar r/o) • (see Islamic calendar).
islamicTabular (Calendar r/o) • The Tabular Islamic calendar (an example is the Fatimid or Misri calendar) is a rule-based variation of the Islamic calendar. It has the same numbering of years and months, but the months are determined by arithmetical rules rather than by observation or astronomical calculations. (Wikipedia)
islamicUmmAlQura (Calendar r/o) • Saudi Arabia uses the sighting method to determine the beginning of each month of the Hijri calendar. Since AH 1419 (1998/99) several official hilal sighting committees have been set up by the government to determine the first visual sighting of the lunar crescent at the beginning of each lunar month. (Wikipedia)
iso8601 (Calendar r/o) • Representation of dates and times is an international standard covering the exchange of date- and time-related data. It was issued by the International Organization for Standardization (ISO) and was first published in 1988. (Wikipedia)
japanese (Calendar r/o) • Japanese calendar types have included a range of official and unofficial systems. At present, Japan uses the Gregorian calendar together with year designations stating the year of the reign of the current Emperor. (Wikipedia)
persian (Calendar r/o) • The Iranian calendars are a succession of calendars invented or used for over two millennia in Iran (Persia). One of the longest chronological records in human history, the Iranian calendar has been modified time and again during its history to suit administrative, climatic, and religious purposes. (Wikipedia)
republicOfChina (Calendar r/o) • The Minguo calendar (Republic of China calendar) is the method of numbering years currently used in Taiwan by officials and other territories under the control of the Republic of China. It was used in mainland China from 1912 until the founding of the People’s Republic of China in 1949. (Wikipedia)
Instance Properties
Properties of an instance of the Calendar class:
identifier (String r/o) • The ISO identifier for the calendar.
locale (Locale or null r/o) • The locale of the calendar.
timeZone (TimeZone r/o) • The time zone of the calendar.
Identifier of Current Calendar
Calendar.current.identifier
//--> "gregorian"
Locale of Current Calendar
Calendar.current.locale
//--> [object Locale: en_US] {calendar: [object Calendar: gregorian], currencyCode: "USD", identifier: "en_US"}
TimeZone of Current Calendar
Calendar.current.timeZone
//--> [object TimeZone: America/Los_Angeles (current)] {abbreviation: "PDT", daylightSavingTime: true, secondsFromGMT: -25200}
Instance Functions
The Calendar class contains a set of special functions for manipulating JavaScript Date objects and data.
dateByAddingDateComponents(date:Date,
components:DateComponents) → (Date or null) • Returns a new Date by adding the given DateComponents, or null if no date could be calculated. dateFromDateComponents(components:DateComponents) → (Date or null) • Returns a new Date object from the given DateComponents, or null if no date could be calculated.
dateComponentsFromDate(date:Date) → (DateComponents) • Returns a new DateComponents for the given Date object.
dateComponentsBetweenDates(start:Date, end:Date) → (DateComponents) • Returns the difference from the start Date to the end Date as DateComponents.
startOfDay(date:Date) → (Date) • Returns a Date object for the first moment of the day containing the given Date according to this Calendar.
Today at Midnight
now = new Date()
today = Calendar.current.startOfDay(now)
//--> Wed Oct 14 2020 00:00:00 GMT-0700 (PDT)
Today at Default Due Time
defaultDueTime = settings.defaultObjectForKey('DefaultDueTime')
timeElements = defaultDueTime.split(":")
today = Calendar.current.startOfDay(new Date())
dc = Calendar.current.dateComponentsFromDate(today)
dc.hour = parseInt(timeElements[0])
dc.minute = parseInt(timeElements[1])
dateDue = Calendar.current.dateFromDateComponents(dc)
DateComponents Class
The DateComponents class represents the elements that comprise a date, such as day, hour, year, and minute.
Constructors
new DateComponents() → (DateComponents) • Creates a new instance of the DateComponents class.
Instance Properties
The properties of an instance of the DateComponents class:
date (Date or null) • The date object of the component
day (Number or null) • The number of days in the component
era (Number or null) • The number of eras in the component
hour (Number or null) • The number of hours in the component
minute (Number or null) • The number of minutes in the component
month (Number or null) • The number of months in the component
nanosecond (Number or null) • The number of nanoseconds in the component
second (Number or null) • The number of seconds in the component
timeZone (TimeZone or null) • The time zone of the component
year (Number or null) • The year of the component
Script examples using the Calendar class instance functions:
Date Components from Date
date = new Date()
dc = Calendar.current.dateComponentsFromDate(date)
dc.month + "/" + dc.day + "/" + dc.year
//--> 8/23/21
Date from Components
dc = new DateComponents()
dc.month = 12
dc.day = 31
dc.year = 2021
date = Calendar.current.dateFromDateComponents(dc)
//--> Fri Dec 31 2021 00:00:00 GMT-0800 (PST)
Components Between Dates
startDate = new Date("8/1/2021")
endDate = new Date("10/15/2021")
result = Calendar.current.dateComponentsBetweenDates(startDate, endDate)
console.log(result.month)
//--> 2
console.log(result.day)
//--> 14
Creating a relative date object 45 days and 17 hours from the start of today:
Generate Relative Future Date/Time
now = new Date()
today = Calendar.current.startOfDay(now)
console.log(today)
//--> Wed Oct 14 2020 00:00:00 GMT-0700 (PDT)
duration = new DateComponents()
duration.day = 45
duration.hour = 17
targetDate = Calendar.current.dateByAddingDateComponents(today, duration)
console.log(targetDate)
//--> Sat Nov 28 2020 17:00:00 GMT-0800 (PST)
A function for retrieving all occurrences of a specified weekday in a specified month. In JavaScript, the index of a weekday is an integer from 0 (Sunday) to 6 (Saturday).
Get All Occurrences of Weekday in Month
function weekdayOccurrencesInMonth(weekdayIndex, monthIndex, yearIndex){
cal = Calendar.current
dc = new DateComponents()
dc.day = 1
dc.month = monthIndex
dc.year = yearIndex
monthLength = new Date(yearIndex, monthIndex, 0).getDate()
matchedDates = new Array()
for (var i = 1; i < (monthLength + 1); i++) {
dc.day = i
var d = cal.dateFromDateComponents(dc)
if (d.getDay() === weekdayIndex){matchedDates.push(d)}
}
return matchedDates
}
Using the function to get the 2nd Monday of May 2021:
2nd Monday of May 2021
var secondMonday = weekdayOccurrencesInMonth(1, 5, 2021)[1]
console.log(secondMonday)
Date Comparison Functions
The properties and functions of the DateComponents class can be used to create comparison functions that check whether the provided date object falls on a specific date or range.
A function that returns true if the provided date/time takes place today:
Does this take place today?
function dateOccursToday(dateToCheck){
cal = Calendar.current
now = new Date()
midnightToday = cal.startOfDay(now)
dc = cal.dateComponentsFromDate(midnightToday)
dc.day = dc.day + 1
midnightTomorrow = cal.dateFromDateComponents(dc)
return ( dateToCheck >= midnightToday && dateToCheck < midnightTomorrow)
}}
A function that returns true if the provided date/time took place yesterday:
Did this take place yesterday?
function dateOccurredYesterday(dateToCheck){
cal = Calendar.current
now = new Date()
midnightToday = cal.startOfDay(now)
dc = cal.dateComponentsFromDate(midnightToday)
dc.day = dc.day - 1
midnightYesterday = cal.dateFromDateComponents(dc)
return ( dateToCheck >= midnightYesterday && dateToCheck < midnightToday)
}
A function that returns true if the provided date/time takes place tomorrow:
Does this take place tomorrow?
function dateOccursTomorrow(dateToCheck){
cal = Calendar.current
now = new Date()
midnightToday = cal.startOfDay(now)
dc = cal.dateComponentsFromDate(midnightToday)
dc.day = dc.day + 1
midnightTomorrow = cal.dateFromDateComponents(dc)
dc = cal.dateComponentsFromDate(midnightToday)
dc.day = dc.day + 2
dayAfterTomorrow = cal.dateFromDateComponents(dc)
return (dateToCheck >= midnightTomorrow && dateToCheck < dayAfterTomorrow)
}}
A function that returns true if the provided date/time takes place next week:
Does this take place next week?
function dateOccursNextWeek(dateToCheck){
fmatr = Formatter.Date.withStyle(Formatter.Date.Style.Short)
weekStart = fmatr.dateFromString('next week')
dc = new DateComponents()
dc.day = 7
followingWeek = Calendar.current.dateByAddingDateComponents(weekStart, dc)
return (dateToCheck >= weekStart && dateToCheck < followingWeek)
}
A function that returns true if the provided date/time takes place this month:
Does this take place this month?
function dateOccursThisMonth(dateToCheck){
cal = Calendar.current
currentMonthIndex = cal.dateComponentsFromDate(new Date()).month
targetMonthIndex = cal.dateComponentsFromDate(dateToCheck).month
return (targetMonthIndex === currentMonthIndex)
}
A function that returns true if the provided date/time takes place next month:
Does this take place next month?
function dateOccursNextMonth(dateToCheck){
cal = Calendar.current
dc = cal.dateComponentsFromDate(new Date())
dc.day = 1
dc.month = dc.month + 1
nextMonth = cal.dateFromDateComponents(dc)
nextMonthIndex = cal.dateComponentsFromDate(nextMonth).month
targetMonthIndex = cal.dateComponentsFromDate(dateToCheck).month
return (nextMonthIndex === targetMonthIndex)
}
A function that returns true if the provided date/time takes place on the provided target date:
Does this take place on target date?
function dateOccursOnTargetDate(dateToCheck, targetDate){
cal = Calendar.current
targetDateStart = cal.startOfDay(targetDate)
dc = cal.dateComponentsFromDate(targetDateStart)
dc.day = dc.day + 1
dayAfterTargetDate = cal.dateFromDateComponents(dc)
return ( dateToCheck >= targetDateStart && dateToCheck < dayAfterTargetDate)
}
Date Library
The date comparison functions shown previously have been combined into an Omni Automation library that can be called from within scripts or plug-ins for any of the Omni applications. TAP|CLICK the “Install” button to install the library plug-in in the indicated Omni application.
The library, once installed, can be loaded and called in scripts using the following statements:
Calling the Date Library
libFile = PlugIn.find("com.omni-automation.all.date-library")
lib = libFile.library("all-date-library")
// lib.function-to-call()
lib.listFunctions()
The library functions:
Date Library Functions
listFunctions()
dateOccursToday(dateToCheck)
dateOccurredYesterday(dateToCheck)
dateOccursTomorrow(dateToCheck)
dateOccursNextWeek(dateToCheck)
dateOccursThisMonth(dateToCheck)
dateOccursNextMonth(dateToCheck)
dateOccursOnTargetDate(dateToCheck,targetDate)
TimeZone Class
Objects that represent a time zone.
Class Properties
The properties of the TimeZone class:
abbreviations (Array of String r/o) • The list of known time zone abbreviations.
TimeZone Abbreviations
TimeZone.abbreviations
//--> ["ADT",
"AKDT", "AKST", "ART", "AST", "BDT", "BRST", "BRT", "BST", "CAT", "CDT", "CEST", "CET", "CLST", "CLT", "COT", "CST", "EAT", "EDT", "EEST", "EET", "EST", "GMT", "GST", "HKT", "HST", "ICT", "IRST", "IST", "JST", "KST", "MDT", "MSD", "MSK", "MST", "NDT", "NST", "NZDT", "NZST", "PDT", "PET", "PHT", "PKT", "PST", "SGT", "TRT", "UTC", "WAT", "WEST", "WET", "WIT"]
Constructor
new TimeZone(abbreviation:String) → (TimeZone) • Make a new TimeZone with the given abbreviation. Note that the returned TimeZone may have a different abbreviation than the passed argument. For example, if one of "PST" or "PDT" is requested that doens't match the current use of daylight savings time, the one that does match will be returned.
Instance Properties
The properties of an instance of the TimeZone class:
abbreviation (String or null r/o) • The abbreviation for the TimeZone.
daylightSavingTime (Boolean r/o) • Returns true if the TimeZone is currently using daylight savings time.
secondsFromGMT (Number r/o) • The current difference in seconds between this TimeZone and GMT.
New TimeZone Instance
tzone = new TimeZone("PST")
//--> [object TimeZone: America/Los_Angeles (current)]
tzone.daylightSavingTime
//--> true
Locale Class
Objects that represent a locale.
Class Properties
The properties of the Locale class:
identifiers (Array of String r/o) • The list of known ISO locale identifiers.
Locale Identifiers
Locale.identifiers
//--> ["eu", "hr_BA", "en_CM", "en_BI", "rw_RW", "ast", "en_SZ", "he_IL", "ar", "uz_Arab", "en_PN", "as", "en_NF", "ks_IN", "es_KY", "rwk_TZ", "zh_Hant_TW", "en_CN", "gsw_LI", "ta_IN", "th_TH", "es_EA", "fr_GF", "ar_001", "en_RW", "tr_TR", "de_CH", "ee_TG", "en_NG", "fr_TG", "az", "fr_SC", "es_HN", "en_AG", "ccp_IN", "ru_KZ", "gsw", "dyo", "so_ET", "zh_Hant_MO", "de_BE", "nus_SS", "km_KH", "my_MM", "mgh_MZ", "ee_GH", "es_EC", "kw_GB", "rm_CH", "en_ME", "nyn", "mk_MK", "bs_Cyrl_BA", "ar_MR", "es_GL", "en_BM", "ms_Arab", "en_AI", "gl_ES", "en_PR", "ff_CM", "ne_IN", "or_IN", "khq_ML", "en_MG", "pt_TL", "en_LC", "iu_CA", "ta_SG", "jmc_TZ", "om_ET", "lv_LV", "es_US", "en_PT", "vai_Latn_LR", "en_NL", "to_TO", "cgg_UG", "en_MH", "ta", "zu_ZA", "shi_Latn_MA", "es_FK", "ar_KM", "en_AL", "brx_IN", "te", "chr_US", "yo_BJ", "fr_VU", "pa", "tg", "kea", "ksh_DE", "sw_CD", "te_IN", "fr_RE", "th", "ur_IN", "yo_NG", "ti", "es_HT", "es_GP", "guz_KE", "tk", "kl_GL", "ksf_CM", "mua_CM", "lag_TZ", "lb", "fr_TN", "es_PA", "pl_PL", "to", "hi_IN", "dje_NE", "es_GQ", "en_BR", "kok_IN", "pl", "fr_GN", "bem", "ha", "ckb", "es_CA", "lg", "tr", "en_PW", "tt", "en_NO", "nyn_UG", "sr_Latn_RS", "gsw_FR", "pa_Guru", "he", "qu_BO", "ps_AF", "lu_CD", "mgo_CM", "sn_ZW", "en_BS", "da", "ps", "ln", "pt", "hi", "lo", "ebu", "de", "gu_IN", "wo_SN", "seh", "en_CX", "en_ZM", "fr_HT", "fr_GP", "pt_GQ", "lt", "lu", "es_TT", "ln_CD", "vai_Latn", "el_GR", "lv", "en_KE", "sbp", "hr", "en_CY", "es_GT", "twq_NE", "zh_Hant_HK", "kln_KE", "fr_GQ", "chr", "hu", "es_UY", "fr_CA", "ms_BN", "en_NR", "mer", "shi", "es_PE", "fr_SN", "bez", "sw_TZ", "wae_CH", "kkj", "hy", "dz_BT", "en_CZ", "teo_KE", "teo", "en_AR", "ar_JO", "yue_Hans_CN", "mer_KE", "khq", "ln_CF", "nn_NO", "es_SR", "en_MO", "ar_TD", "dz", "ses", "en_BW", "en_AS", "ar_IL", "es_BB", "bo_CN", "nnh", "teo_UG", "hy_AM", "ln_CG", "sr_Latn_BA", "en_MP", "ksb_TZ", "ar_SA", "smn_FI", "ar_LY", "en_AT", "so_KE", "fr_CD", "af_NA", "en_NU", "es_PH", "en_KI", "en_JE", "lkt", "en_AU", "fa_IR", "pt_FR", "uz_Latn_UZ", "zh_Hans_CN", "ewo_CM", "fr_PF", "ca_IT", "es_GY", "en_BZ", "ar_KW", "pt_GW", "fr_FR", "am_ET", "en_VC", "es_DM", "fr_DJ", "fr_CF", "es_SV", "en_MS", "pt_ST", "ar_SD", "luy_KE", "gd_GB", "de_LI", "it_VA", "fr_CG", "pt_CH", "ckb_IQ", "zh_Hans_SG", "en_MT", "ha_NE", "en_ID", "ewo", "af_ZA", "os_GE", "om_KE", "nl_SR", "es_ES", "es_DO", "ar_IQ", "fr_CH", "nnh_CM", "es_SX", "es_419", "en_MU", "en_US_POSIX", "yav_CM", "luo_KE", "dua_CM", "et_EE", "en_IE", "ak_GH", "rwk", "es_CL", "kea_CV", "fr_CI", "ckb_IR", "fr_BE", "se", "en_NZ", "en_MV", "en_LR", "es_PM", "en_KN", "nb_SJ", "ha_NG", "sg", "sr_Cyrl_RS", "ru_RU", "en_ZW", "sv_AX", "ga_IE", "si", "wo", "en_VG", "ff_MR", "ky_KG", "agq_CM", "mzn", "fr_BF", "naq_NA", "mr_IN", "en_MW", "de_AT", "az_Latn", "en_LS", "ka", "sk", "sl", "sn", "sr_Latn_ME", "fr_NC", "so", "is_IS", "twq", "ig_NG", "sq", "fo_FO", "sr", "tzm", "ga", "om", "en_LT", "bas_CM", "se_NO", "ki", "nl_BE", "ar_QA", "gd", "sv", "kk", "rn_BI", "es_CO", "az_Latn_AZ", "kl", "or", "es_AG", "ca", "en_VI", "km", "os", "sw", "en_MY", "kn", "en_LU", "fr_SY", "ar_TN", "en_JM", "fr_PM", "ko", "fr_NE", "ce", "fr_MA", "gl", "ru_MD", "es_BL", "saq_KE", "ks", "fr_CM", "lb_LU", "gv_IM", "fr_BI", "en_LV", "en_KR", "es_NI", "en_GB", "kw", "nl_SX", "dav_KE", "tr_CY", "ky", "en_UG", "es_BM", "en_TC", "es_AI", "ar_EG", "fr_BJ", "gu", "es_PR", "fr_RW", "gv", "lrc_IQ", "sr_Cyrl_BA", "es_MF", "fr_MC", "cs", "bez_TZ", "es_CR", "asa_TZ", "ar_EH", "fo_DK", "ms_Arab_BN", "ccp", "en_JP", "sbp_TZ", "en_IL", "lt_LT", "mfe", "en_GD", "es_LC", "cy", "ug_CN", "ca_FR", "es_BO", "en_SA", "fr_BL", "bn_IN", "uz_Cyrl_UZ", "lrc_IR", "az_Cyrl", "en_IM", "sw_KE", "en_SB", "pa_Arab", "ur_PK", "haw_US", "ar_SO", "en_IN", "fil", "fr_MF", "en_WS", "es_CU", "es_BQ", "ja_JP", "fy_NL", "en_SC", "yue_Hant_HK", "en_IO", "pt_PT", "en_HK", "en_GG", "fr_MG", "de_LU", "tzm_MA", "es_BR", "en_TH", "en_SD", "nds_DE", "shi_Tfng", "ln_AO", "as_IN", "en_GH", "ms_MY", "ro_RO", "jgo_CM", "es_CW", "dua", "en_UM", "es_BS", "en_SE", "kn_IN", "en_KY", "vun_TZ", "kln", "lrc", "en_GI", "ca_ES", "rof", "pt_CV", "kok", "pt_BR", "ar_DJ", "yi_001", "fi_FI", "zh", "es_PY", "ar_SS", "mua", "sr_Cyrl_ME", "vai_Vaii_LR", "en_001", "nl_NL", "en_TK", "fr_DZ", "en_SG", "ca_AD", "si_LK", "sv_SE", "pt_AO", "vi", "xog_UG", "xog", "en_IS", "nb", "seh_MZ", "es_AR", "sk_SK", "en_SH", "ti_ER", "nd", "az_Cyrl_AZ", "zu", "ne", "nd_ZW", "el_CY", "en_IT", "nl_BQ", "da_GL", "ja", "rm", "fr_ML", "rn", "en_VU", "rof_TZ", "ro", "ebu_KE", "ru_KG", "en_SI", "sg_CF", "mfe_MU", "nl", "brx", "bs_Latn", "fa", "zgh_MA", "en_GM", "shi_Latn", "en_FI", "nn", "en_EE", "ru", "yue", "kam_KE", "fur", "vai_Vaii", "ar_ER", "rw", "ti_ET", "ff", "luo", "fa_AF", "nl_CW", "es_MQ", "en_HR", "en_FJ", "fi", "pt_MO", "be", "en_US", "en_TO", "en_SK", "bg", "ru_BY", "it_IT", "ml_IN", "gsw_CH", "qu_EC", "fo", "sv_FI", "en_FK", "nus", "ta_LK", "vun", "sr_Latn", "es_BZ", "fr", "en_SL", "bm", "es_VC", "ar_BH", "guz", "bn", "bo", "ar_SY", "es_MS", "lo_LA", "ne_NP", "uz_Latn", "be_BY", "es_IC", "sr_Latn_XK", "ar_MA", "pa_Guru_IN", "br", "luy", "kde_TZ", "es_AW", "bs", "fy", "fur_IT", "hu_HU", "ar_AE", "en_HU", "sah_RU", "zh_Hans", "en_FM", "fr_MQ", "ko_KP", "en_150", "en_DE", "ce_RU", "en_CA", "hsb_DE", "sq_AL", "en_TR", "ro_MD", "es_VE", "tg_TJ", "fr_WF", "mt_MT", "kab", "nmg_CM", "ms_SG", "en_GR", "ru_UA", "fr_MR", "zh_Hans_MO", "de_IT", "ccp_BD", "ff_GN", "bs_Cyrl", "tt_RU", "nds_NL", "es_KN", "sw_UG", "yue_Hans", "ko_KR", "en_DG", "bo_IN", "en_CC", "shi_Tfng_MA", "lag", "it_SM", "os_RU", "en_TT", "ms_Arab_MY", "sq_MK", "es_VG", "bem_ZM", "kde", "ar_OM", "kk_KZ", "cgg", "bas", "kam", "wae", "es_MX", "sah", "zh_Hant", "en_GU", "fr_MU", "fr_KM", "ar_LB", "en_BA", "en_TV", "sr_Cyrl", "mzn_IR", "es_VI", "dje", "kab_DZ", "fil_PH", "se_SE", "vai", "hr_HR", "bs_Latn_BA", "nl_AW", "dav", "so_SO", "ar_PS", "en_FR", "uz_Cyrl", "ff_SN", "en_BB", "ki_KE", "en_TW", "naq", "en_SS", "mg_MG", "mas_KE", "en_RO", "en_PG", "mgh", "dyo_SN", "mas", "agq", "bn_BD", "haw", "yi", "nb_NO", "da_DK", "en_DK", "saq", "ug", "cy_GB", "fr_YT", "jmc", "ses_ML", "en_PH", "de_DE", "ar_YE", "es_TC", "bm_ML", "yo", "lkt_US", "uz_Arab_AF", "jgo", "sl_SI", "pt_LU", "uk", "en_CH", "asa", "en_BD", "lg_UG", "nds", "qu_PE", "mgo", "id_ID", "en_NA", "en_GY", "zgh", "pt_MZ", "fr_LU", "dsb", "mas_TZ", "en_DM", "ta_MY", "es_GD", "en_BE", "mg", "ur", "fr_GA", "ka_GE", "nmg", "en_TZ", "eu_ES", "ar_DZ", "id", "so_DJ", "hsb", "yav", "mk", "pa_Arab_PK", "ml", "en_ER", "ig", "se_FI", "mn", "ksb", "uz", "vi_VN", "ii", "qu", "en_PK", "ee", "ast_ES", "yue_Hant", "mr", "ms", "en_ES", "ha_GH", "it_CH", "sq_XK", "mt", "en_CK", "br_FR", "en_BG", "es_GF", "tk_TM", "sr_Cyrl_XK", "ksf", "en_SX", "bg_BG", "en_PL", "af", "el", "cs_CZ", "fr_TD", "zh_Hans_HK", "is", "ksh", "my", "mn_MN", "en", "it", "dsb_DE", "ii_CN", "eo", "iu", "en_ZA", "smn", "en_AD", "ak", "en_RU", "kkj_CM", "am", "es", "et", "uk_UA"]
Constructors
new Locale(identifier:String) → (Locale) • Make a new Locale with the given identifier.
Instance Properties
The properties of an instance of the Locale class:
calendar (Calendar r/o) • The calendar instance associated with the locale.
identifier (String r/o) • The unique identifier string for the locale.
currencyCode (String or null r/o) • The currency code for the locale.
New Locale Instance
var loc = new Locale("en_US")
loc.calendar
//--> [object Calendar: gregorian]
Using the currencyCode property of the Locale class to retrieve the currency code for Sweden:
Currency Code for Sweden
new Locale("sv_SE").currencyCode
//--> "SEK"
Using the currencyCode property with the Decimal Formatter class to express a numeric amount as Swedish Kroner:
Amount in Swedish Kroner
currencyCode = new Locale("sv_SE").currencyCode
fmtr = Formatter.Decimal.currency(currencyCode)
dVal = Decimal.fromString('12345')
fmtr.stringFromDecimal(dVal)
//--> SEK12,345.00
Reference Links
ISO 639-1 codes (Locale identifiers)
Currency Codes
Currency Codes
"AED" "United Arab Emirates Dirham"
"AFN" "Afghan Afghani"
"ALL" "Albanian Lek"
"AMD" "Armenian Dram"
"ANG" "Netherlands Antillean Guilder"
"AOA" "Angolan Kwanza"
"ARS" "Argentine Peso"
"AUD" "Australian Dollar"
"AWG" "Aruban Florin"
"AZN" "Azerbaijani Manat"
"BAM" "Bosnia-Herzegovina Convertible Mark"
"BBD" "Barbadian Dollar"
"BDT" "Bangladeshi Taka"
"BGN" "Bulgarian Lev"
"BHD" "Bahraini Dinar"
"BIF" "Burundian Franc"
"BMD" "Bermudan Dollar"
"BND" "Brunei Dollar"
"BOB" "Bolivian Boliviano"
"BRL" "Brazilian Real"
"BSD" "Bahamian Dollar"
"BTC" "Bitcoin"
"BTN" "Bhutanese Ngultrum"
"BWP" "Botswanan Pula"
"BYN" "Belarusian Ruble"
"BZD" "Belize Dollar"
"CAD" "Canadian Dollar"
"CDF" "Congolese Franc"
"CHF" "Swiss Franc"
"CLF" "Chilean Unit of Account (UF)"
"CLP" "Chilean Peso"
"CNH" "Chinese Yuan (Offshore)"
"CNY" "Chinese Yuan"
"COP" "Colombian Peso"
"CRC" "Costa Rican Colón"
"CUC" "Cuban Convertible Peso"
"CUP" "Cuban Peso"
"CVE" "Cape Verdean Escudo"
"CZK" "Czech Republic Koruna"
"DJF" "Djiboutian Franc"
"DKK" "Danish Krone"
"DOP" "Dominican Peso"
"DZD" "Algerian Dinar"
"EGP" "Egyptian Pound"
"ERN" "Eritrean Nakfa"
"ETB" "Ethiopian Birr"
"EUR" "Euro"
"FJD" "Fijian Dollar"
"FKP" "Falkland Islands Pound"
"GBP" "British Pound Sterling"
"GEL" "Georgian Lari"
"GGP" "Guernsey Pound"
"GHS" "Ghanaian Cedi"
"GIP" "Gibraltar Pound"
"GMD" "Gambian Dalasi"
"GNF" "Guinean Franc"
"GTQ" "Guatemalan Quetzal"
"GYD" "Guyanaese Dollar"
"HKD" "Hong Kong Dollar"
"HNL" "Honduran Lempira"
"HRK" "Croatian Kuna"
"HTG" "Haitian Gourde"
"HUF" "Hungarian Forint"
"IDR" "Indonesian Rupiah"
"ILS" "Israeli New Sheqel"
"IMP" "Manx pound"
"INR" "Indian Rupee"
"IQD" "Iraqi Dinar"
"IRR" "Iranian Rial"
"ISK" "Icelandic Króna"
"JEP" "Jersey Pound"
"JMD" "Jamaican Dollar"
"JOD" "Jordanian Dinar"
"JPY" "Japanese Yen"
"KES" "Kenyan Shilling"
"KGS" "Kyrgystani Som"
"KHR" "Cambodian Riel"
"KMF" "Comorian Franc"
"KPW" "North Korean Won"
"KRW" "South Korean Won"
"KWD" "Kuwaiti Dinar"
"KYD" "Cayman Islands Dollar"
"KZT" "Kazakhstani Tenge"
"LAK" "Laotian Kip"
"LBP" "Lebanese Pound"
"LKR" "Sri Lankan Rupee"
"LRD" "Liberian Dollar"
"LSL" "Lesotho Loti"
"LYD" "Libyan Dinar"
"MAD" "Moroccan Dirham"
"MDL" "Moldovan Leu"
"MGA" "Malagasy Ariary"
"MKD" "Macedonian Denar"
"MMK" "Myanma Kyat"
"MNT" "Mongolian Tugrik"
"MOP" "Macanese Pataca"
"MRO" "Mauritanian Ouguiya (pre-2018)"
"MRU" "Mauritanian Ouguiya"
"MUR" "Mauritian Rupee"
"MVR" "Maldivian Rufiyaa"
"MWK" "Malawian Kwacha"
"MXN" "Mexican Peso"
"MYR" "Malaysian Ringgit"
"MZN" "Mozambican Metical"
"NAD" "Namibian Dollar"
"NGN" "Nigerian Naira"
"NIO" "Nicaraguan Córdoba"
"NOK" "Norwegian Krone"
"NPR" "Nepalese Rupee"
"NZD" "New Zealand Dollar"
"OMR" "Omani Rial"
"PAB" "Panamanian Balboa"
"PEN" "Peruvian Nuevo Sol"
"PGK" "Papua New Guinean Kina"
"PHP" "Philippine Peso"
"PKR" "Pakistani Rupee"
"PLN" "Polish Zloty"
"PYG" "Paraguayan Guarani"
"QAR" "Qatari Rial"
"RON" "Romanian Leu"
"RSD" "Serbian Dinar"
"RUB" "Russian Ruble"
"RWF" "Rwandan Franc"
"SAR" "Saudi Riyal"
"SBD" "Solomon Islands Dollar"
"SCR" "Seychellois Rupee"
"SDG" "Sudanese Pound"
"SEK" "Swedish Krona"
"SGD" "Singapore Dollar"
"SHP" "Saint Helena Pound"
"SLL" "Sierra Leonean Leone"
"SOS" "Somali Shilling"
"SRD" "Surinamese Dollar"
"SSP" "South Sudanese Pound"
"STD" "São Tomé and Príncipe Dobra (pre-2018)"
"STN" "São Tomé and Príncipe Dobra"
"SVC" "Salvadoran Colón"
"SYP" "Syrian Pound"
"SZL" "Swazi Lilangeni"
"THB" "Thai Baht"
"TJS" "Tajikistani Somoni"
"TMT" "Turkmenistani Manat"
"TND" "Tunisian Dinar"
"TOP" "Tongan Pa anga"
"TRY" "Turkish Lira"
"TTD" "Trinidad and Tobago Dollar"
"TWD" "New Taiwan Dollar"
"TZS" "Tanzanian Shilling"
"UAH" "Ukrainian Hryvnia"
"UGX" "Ugandan Shilling"
"USD" "United States Dollar"
"UYU" "Uruguayan Peso"
"UZS" "Uzbekistan Som"
"VEF" "Venezuelan Bolívar Fuerte (Old)"
"VES" "Venezuelan Bolívar Soberano"
"VND" "Vietnamese Dong"
"VUV" "Vanuatu Vatu"
"WST" "Samoan Tala"
"XAF" "CFA Franc BEAC"
"XAG" "Silver Ounce"
"XAU" "Gold Ounce"
"XCD" "East Caribbean Dollar"
"XDR" "Special Drawing Rights"
"XOF" "CFA Franc BCEAO"
"XPD" "Palladium Ounce"
"XPF" "CFP Franc"
"XPT" "Platinum Ounce"
"YER" "Yemeni Rial"
"ZAR" "South African Rand"
"ZMW" "Zambian Kwacha"
"ZWL" "Zimbabwean Dollar"