-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[Term Entry] Javascript Method : .toLocaleString() #4608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0c9d9de
Create toLocaleString term for JavaScript toLocaleString method
lamiaelhbari 0bbc842
fix formatting file as per changes on pull request
lamiaelhbari 73fcd41
Update toLocaleString.md
lamiaelhbari d97801b
Merge branch 'main' into toLocaleStringMethod
lamiaelhbari 6602fd9
Update toLocaleString.md
mamtawardhani 9d25fba
Update toLocaleString.md
mamtawardhani 97feb53
Update toLocaleString.md
mamtawardhani 3c7d6de
Update toLocaleString.md
mamtawardhani fd73ca8
Update toLocaleString.md
mamtawardhani 2cdc94a
Merge branch 'main' into toLocaleStringMethod
lamiaelhbari e503c24
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt 555eda4
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt cd1c87e
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt 84d3aab
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt bd938b9
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt 5946cbf
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt f0e77db
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt 9592c4a
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt c2125d0
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt 89ef5fb
Merge branch 'main' into toLocaleStringMethod
avdhoottt 93cd5c8
Format + Lint Error
avdhoottt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| Title: '.toLocaleString()' | ||
| Description: 'Returns a string formatted based on the locale for a Date object in JavaScript.' | ||
| Subjects: | ||
| - 'Computer Science' | ||
| - 'Web Development' | ||
| Tags: | ||
| - 'Date' | ||
| - 'Methods' | ||
| - 'Strings' | ||
| CatalogContent: | ||
| - 'introduction-to-javascript' | ||
| - 'paths/front-end-engineer-career-path' | ||
| --- | ||
|
|
||
| In JavaScript, the **`.toLocaleString()`** method formats a [`Date`](https://www.codecademy.com/resources/docs/javascript/dates) object as a string according to the specified locale, considering cultural settings such as `language` and `date/time` formatting preferences specific to the chosen region or country. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```pseudo | ||
| dateObj.toLocaleString(locales, options) | ||
| ``` | ||
|
|
||
| - `dateObj`: A `Date` object representing the date and time to be formatted as a string based on the specified locale. | ||
| - `locales`: A `string` or an `array of strings` that specifies one or more `locales` or language tags for formatting the date. | ||
| - `options`: An object that allows customizing the formatting behavior, such as specifying the format for `date`, `time`, `numeric values`, and more. | ||
|
|
||
| > **Note:** Both the `locales` and `options` parameters in the `.toLocaleString()` method are optional. If the parameters are not provided, the method will use `default` values based on the runtime environment. | ||
|
|
||
| ## Example | ||
|
|
||
| In the example below, `toLocaleString()` formats the current `date` and `time` according to the long date format with the full `weekday`, `month`, `day`, and `year` in English (United States) `locale`: | ||
|
|
||
| ```js | ||
| const specificDate = new Date('2024-05-16'); | ||
| const locale = 'en-US'; | ||
| const options = { | ||
| weekday: 'long', | ||
| year: 'numeric', | ||
| month: 'long', | ||
| day: 'numeric', | ||
| }; | ||
| console.log(specificDate.toLocaleDateString(locale, options)); | ||
| ``` | ||
|
|
||
| The code above produces the following output: | ||
|
|
||
| ```shell | ||
| Thursday, May 16, 2024 | ||
| ``` | ||
|
|
||
| ## Codebyte Example | ||
|
|
||
| In the following example, `.toLocaleString()` formats the current date and time with the full `weekday`, `year`, `month`, `day`, `hour`, `minute`, and `second` in French (Morocco) locale (fr-MA): | ||
|
|
||
| ```codebyte/javascript | ||
| const currentDate = new Date(); | ||
|
|
||
| const locale = 'fr-MA'; | ||
| const options = { | ||
| weekday: 'long', | ||
| year: 'numeric', | ||
| month: 'long', | ||
| day: 'numeric', | ||
| hour: 'numeric', | ||
| minute: 'numeric', | ||
| second: 'numeric' | ||
| }; | ||
| console.log(currentDate.toLocaleString(locale, options)); | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.