Skip to content
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 May 5, 2024
0bbc842
fix formatting file as per changes on pull request
lamiaelhbari May 6, 2024
73fcd41
Update toLocaleString.md
lamiaelhbari May 6, 2024
d97801b
Merge branch 'main' into toLocaleStringMethod
lamiaelhbari May 15, 2024
6602fd9
Update toLocaleString.md
mamtawardhani May 15, 2024
9d25fba
Update toLocaleString.md
mamtawardhani May 15, 2024
97feb53
Update toLocaleString.md
mamtawardhani May 15, 2024
3c7d6de
Update toLocaleString.md
mamtawardhani May 15, 2024
fd73ca8
Update toLocaleString.md
mamtawardhani May 15, 2024
2cdc94a
Merge branch 'main' into toLocaleStringMethod
lamiaelhbari May 16, 2024
e503c24
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
555eda4
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
cd1c87e
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
84d3aab
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
bd938b9
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
5946cbf
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
f0e77db
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
9592c4a
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
c2125d0
Update content/javascript/concepts/dates/terms/toLocaleString/toLocal…
avdhoottt Jun 4, 2024
89ef5fb
Merge branch 'main' into toLocaleStringMethod
avdhoottt Jun 4, 2024
93cd5c8
Format + Lint Error
avdhoottt Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
```