---
schema_version: "1"
id: 5a023d1b3948bae44bcf5cd6454586fdad6fb65a9c41b6cfe418ac73c3be73ce
title: Use Locale-Neutral Methods in Code
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/admin_locales_code_methods.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.admin_locales_code_methods.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 8dd537350b67eaddf96b9f29b2be253408a7b3fac5c713ebacfcefe149621c04
description: Data formats can change based on the user’s locale, adoption of new standards, or updates to the standard locale formats. To avoid errors when a locale format changes, use standard methods to handle this data in your code. If your code formats the data using the user’s locale, apply the format after all other processing is complete.
products:
  - Salesforce Platform
  - Cross Cloud
release: "264"
---
# Use Locale-Neutral Methods in Code

Data formats can change based on the user’s locale, adoption of new standards, or updates to the standard locale formats. To avoid errors when a locale format changes, use standard methods to handle this data in your code. If your code formats the data using the user’s locale, apply the format after all other processing is complete.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: all editions</td></tr></tbody></table>

To search your Salesforce code, download the metadata. Then use a command-line interface such as [Salesforce CLI](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm).

A user’s locale determines the formats for these types of data: address, currency, date, datetime, name, integer, and time. The start day of the week is also based on the user’s locale.

When you migrate from Oracle’s Java Development Kit (JDK) locale formats to the International Components for Unicode (ICU) locale formats, the currency, date, datetime, integer, and time formats change for some locales.

Also, locale formats are regularly updated to match the newest international standards. And users can update their locale to match their current location or preference.

To prevent issues with your custom code due to locale format changes, follow these guidelines.

- Use standard methods to call these formats. For example, when handling dates in Apex, use the Date data type.
- When handling these data types in your code, use standard methods to extract components. For example, when you want to extract the month from a date format in Apex, use the `month()` method on the Date class. Similarly, handle integers and currency values as unformatted integers until you must format them.
- If your code performs additional processing on a value, use a locale-neutral format. For example, in Apex, use `format(string dataFormat)` or `format(string dataFormat, string timezone)`.
- Make the transformation of data to the user’s preferred locale format the last step in handling that data. For example, when calculating a future date in Apex, use the `format()` method of the Date class after the calculation.
- Apex `format()` methods, such as `DateTime.format()` return values in the context user’s locale. If subsequent code expects data in a particular locale format, specify the format explicitly. For example, to pass a time in a format such as `10:15 a` in Apex, use `DateTime.format('h:mm a')`. Because this example passes the string argument 'h:mm a' to the format function, the datetime is formatted according to the supplied format regardless of the context user’s locale.
- When constructing delimited lists, put any locale data that can contain a comma in quotes.

Here are some examples of code that return formats in the user’s preferred locale format.

- Apex: the `format()` method in the Date, DateTime, and Integer classes
- Aura Lightning Components: the `$Locale` global variable
- Lightning Web Component Internationalization properties

#### See Also

- [Example Code with Locale-Formatted Data](https://help.salesforce.com/s/articleView?id=xcloud.admin_locales_code_examples.htm&release=264.0.0&type=5 "Review examples of code that handles data that can be formatted based on the user’s locale. See how code can break when it relies on a specific format for dates, times, and currencies. And review examples of how to fix these issues by using standard methods for handling these types of data.")
- [Update Your Integrations for New Locale Formats](https://help.salesforce.com/s/articleView?id=xcloud.admin_locales_code_integrations.htm&release=264.0.0&type=5 "If you integrate data from external systems into Salesforce or if you send Salesforce data to external third parties, use locale-neutral formats whenever possible in the related code. When locale formats change, review the code that handles the affected formats.")
- [_Apex Reference Guide_](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_ref_guide.htm)
- [_Lightning Aura Components Developer Guide_: $Locale](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_locale_value_provider.htm)
- [_Salesforce Lightning Component Library_: Access Internationalization Properties](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/create_i18n)