Skip to content

Conversation

@lamiaelhbari
Copy link
Contributor

@lamiaelhbari lamiaelhbari commented May 5, 2024

Description

Issue Solved

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@CLAassistant
Copy link

CLAassistant commented May 5, 2024

CLA assistant check
All committers have signed the CLA.

@mamtawardhani mamtawardhani self-assigned this May 5, 2024
@mamtawardhani mamtawardhani added javascript JavaScript entries new entry New entry or entries status: under review Issue or PR is currently being reviewed labels May 5, 2024
Copy link
Collaborator

@mamtawardhani mamtawardhani left a 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!

Comment on lines 1 to 16
---
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'
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
---
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'
---


# 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines 24 to 26
```js {copy}
toLocaleString(locales [, options])
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```js {copy}
toLocaleString(locales [, options])
```
```js
dateObj.toLocaleString(locales, options)

Comment on lines 27 to 29
- `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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `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.

Comment on lines 45 to 70

## 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" .
```


Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```codebyte/js
```codebyte/javascript

Comment on lines 88 to 89


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 43 to 44
Depending on the current `date` and `time` when the code is executed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Depending on the current `date` and `time` when the code is executed.

weekday: 'long',
};

console.log(date.toLocaleDateString(locale, options));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(date.toLocaleDateString(locale, options));
console.log(date.toLocaleString(locale, options));

@lamiaelhbari
Copy link
Contributor Author

Hi @mamtawardhani , Thank you for your detailed suggestions!

I will take your comments into consideration and make the necessary changes as soon as possible.
I will keep you informed of the progress. If you have any questions or requests, please feel free to let me know.

Thanks again for your assistance!

@mamtawardhani
Copy link
Collaborator

Hello @lamiaelhbari! Could you please make the required changes at your earliest convenience?
Thanks!

@ishg-153 ishg-153 linked an issue May 15, 2024 that may be closed by this pull request
3 tasks
@lamiaelhbari
Copy link
Contributor Author

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!

Copy link
Collaborator

@mamtawardhani mamtawardhani left a 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

Copy link
Collaborator

@avdhoottt avdhoottt left a 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.

@mamtawardhani
Copy link
Collaborator

Hey @lamiaelhbari are you still working on this?

Copy link
Collaborator

@avdhoottt avdhoottt left a 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.

@avdhoottt avdhoottt merged commit dd55979 into Codecademy:main Jun 4, 2024
@github-actions
Copy link

github-actions bot commented Jun 4, 2024

👋 @lamiaelhbari
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

🎉 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.
If you're appearing as anonymous and want to be credited, see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Entry] JavaScript Dates: .toLocaleString()

4 participants