-
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
Conversation
mamtawardhani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @lamiaelhbari, thank you for contributing to Codecademy Docs!
The entry is well written, however, a few things are to be looked at:
(1) Please sign the CLA.
(2) I've provided suggestions and comments on various parts of this entry, please review and modify them at your earliest convenience.
Thank you!
| --- | ||
| Title: 'toLocaleString Method' | ||
| Description: 'A method to format a Date object as a string, based on the locale.' | ||
| Subjects: | ||
| - 'Computer Science' | ||
| - 'Web Development' | ||
|
|
||
| Tags: | ||
| - 'JavaScript' | ||
| - 'Methods' | ||
| - 'Date' | ||
|
|
||
| CatalogContent: | ||
| - 'learn-javascript' | ||
| - 'paths/web-development' | ||
| --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| --- | |
| Title: 'toLocaleString Method' | |
| Description: 'A method to format a Date object as a string, based on the locale.' | |
| Subjects: | |
| - 'Computer Science' | |
| - 'Web Development' | |
| Tags: | |
| - 'JavaScript' | |
| - 'Methods' | |
| - 'Date' | |
| CatalogContent: | |
| - 'learn-javascript' | |
| - 'paths/web-development' | |
| --- | |
| --- | |
| 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' | |
| --- |
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
|
|
||
| # toLocaleString() Method : | ||
|
|
||
| The `.toLocaleString()` method in JavaScript is used to format a [`Date` object](https://www.codecademy.com/resources/docs/javascript/dates), as a string based on the specified locale. This means it takes into account cultural settings such as `language` and `date/time` formatting preferences specific to the selected region or country. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The `.toLocaleString()` method in JavaScript is used to format a [`Date` object](https://www.codecademy.com/resources/docs/javascript/dates), as a string based on the specified locale. This means it takes into account cultural settings such as `language` and `date/time` formatting preferences specific to the selected region or country. | |
| The `.toLocaleString()` method in JavaScript 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. |
| ```js {copy} | ||
| toLocaleString(locales [, options]) | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```js {copy} | |
| toLocaleString(locales [, options]) | |
| ``` | |
| ```js | |
| dateObj.toLocaleString(locales, options) |
| - `locales` : Represents the `locale or locales` to use when formatting the `date`. | ||
| - `options` : Contains additional formatting options for the `date`, such as the format of the `weekday`, `month`, `year`, etc. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - `locales` : Represents the `locale or locales` to use when formatting the `date`. | |
| - `options` : Contains additional formatting options for the `date`, such as the format of the `weekday`, `month`, `year`, etc. | |
| - `dateObj`: The `Date` object used to format as a string based on the 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. |
|
|
||
| ## Runnable Code Example : | ||
| ```js {copy} | ||
| const date = new Date(1985,7,4); | ||
| const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; | ||
|
|
||
| // Formatting for English (United States) : | ||
| console.log(date.toLocaleString('en-US', options)); | ||
|
|
||
| // Formatting for Korean (South Korea) : | ||
| console.log(date.toLocaleString('ko-KR', options)); | ||
|
|
||
| // Formatting for Hindi (India) : | ||
| console.log(date.toLocaleString('hi-IN', options)); | ||
| ``` | ||
| In this example, we use `toLocaleString()` to format the current `date` and `time` with the specified formatting options for `English` (United States), `Korean` (South Korea), and `Hindi` (India). | ||
|
|
||
|
|
||
| ```shell {copy} | ||
| // Output : | ||
| For English (United States): "Sunday, August 4, 1985" . | ||
| For Korean (South Korea): "1985년 8월 4일 일요일" . | ||
| For Hindi (India): "रविवार, 4 अगस्त 1985" . | ||
| ``` | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines 45 to 70 can be removed. Only one ## Example and one ## Codebyte Example is needed.
|
|
||
| In the following example the variables `locale` and `options` can be modified, to print the `Date` in a custom format: | ||
|
|
||
| ```codebyte/js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```codebyte/js | |
| ```codebyte/javascript |
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Depending on the current `date` and `time` when the code is executed. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Depending on the current `date` and `time` when the code is executed. |
| weekday: 'long', | ||
| }; | ||
|
|
||
| console.log(date.toLocaleDateString(locale, options)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| console.log(date.toLocaleDateString(locale, options)); | |
| console.log(date.toLocaleString(locale, options)); |
|
Hi @mamtawardhani , Thank you for your detailed suggestions! I will take your comments into consideration and make the necessary changes as soon as possible. Thanks again for your assistance! |
|
Hello @lamiaelhbari! Could you please make the required changes at your earliest convenience? |
|
Hello @mamatawardhani, I have addressed all the requested changes and updated the branch. All CI checks have passed successfully. Could you please review the updates and approve the workflow? Thank you for your time and assistance! |
mamtawardhani
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lamiaelhbari for making the required changes!
Looks for the second review
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
avdhoottt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @lamiaelhbari, excellent entry! I have suggested some changes, please make them.
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Outdated
Show resolved
Hide resolved
|
Hey @lamiaelhbari are you still working on this? |
content/javascript/concepts/dates/terms/toLocaleString/toLocaleString.md
Show resolved
Hide resolved
avdhoottt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes and merged this PR myself as the author is not responding.
|
👋 @lamiaelhbari 🎉 Your contribution(s) can be seen here: https://www.codecademy.com/resources/docs/javascript/dates/toLocaleString Please note it may take a little while for changes to become visible. |
Description
Issue Solved
Type of Change
Checklist
mainbranch.Issues Solvedsection.