JavaScript Reference

Quick Reference

The Date toLocaleString() method returns a date and time as a string, using locale settings.

<!-- html element to place output -->
<p id="my_output"></p>
// variable
let my_date = new Date();

// set date
let text = my_date.toLocaleString();

// output to the HTML element
document.getElementById('my_output').innerHTML = text;

Output

8/22/2022, 4:54:31 PM

Syntax

Date.toLocaleString(locales, options)

Parameters

ValueDescription
locales
  • ar-SA Arabic
  • bn-BD Bangla
  • bn-IN Bangla
  • cs-CZ Czech
  • da-DK Danish
  • de-AT Austrian German
  • de-CH "Swiss" German
  • de-DE Standard German
  • el-GR Modern Greek
  • en-AU Australian English
  • en-CA Canadian English
  • en-GB British English
  • en-IE Irish English
  • en-IN Indian English
  • en-NZ New Zealand English
  • en-US US English
  • en-ZA English (South Africa)
  • es-AR Argentine Spanish
  • es-CL Chilean Spanish
  • es-CO Colombian Spanish
  • es-ES Castilian Spanish (as spoken in Central-Northern Spain)
  • es-MX Mexican Spanish
  • es-US American Spanish
  • fi-FI Finnish
  • fr-BE Belgian French
  • fr-CA Canadian French
  • fr-CH "Swiss" French
  • fr-FR Standard French
  • he-IL Hebrew
  • hi-IN Hindi
  • hu-HU Hungarian
  • id-ID Indonesian
  • it-CH "Swiss" Italian
  • it-IT Standard Italian
  • ja-JP Japanese
  • ko-KR Korean (Republic of Korea)
  • nl-BE Belgian Dutch
  • nl-NL Standard Dutch
  • no-NO Norwegian
  • pl-PL Polish
  • pt-BR Brazilian Portuguese
  • pt-PT European Portuguese (Portugal)
  • ro-RO Romanian
  • ru-RU Russian
  • sk-SK Slovak
  • sv-SE Swedish
  • ta-IN Indian Tamil
  • ta-LK Sri Lankan Tamil
  • th-TH Thai
  • tr-TR Turkish
  • zh-CN Mainland China (simplified characters)
  • zh-HK Hong Kong (traditional characters)
  • zh-TW Taiwan (traditional characters)
optionsdateStyle:
  • "full"
  • "long"
  • "medium"
  • "short"
timeStyle:
  • "full"
  • "long"
  • "medium"
  • "short"
localeMatcher:
  • "best-fit" (default)
  • "lookup"
timeZone -

hour12:
  • false
  • true
hourCycle:
  • "h11"
  • "h12"
  • "h23"
  • "h24"
formatMatcher:
  • "basic"
  • "best-fit"
weekday:
  • "long"
  • "short"
  • "narrow"
year:
  • "2-digit"
  • "numeric"
month:
  • "2-digit"
  • "long"
  • "narrow"
  • "numeric"
  • "short"
day:
  • "2-digit"
  • "numeric"
hour:
  • "2-digit"
  • "numeric"
minute:
  • "2-digit"
  • "numeric"
second:
  • "2-digit"
  • "numeric"
timeZoneName:
  • "long"
  • "short"

JavaScript Notes:

  • When using JavaScript, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
  • JavaScript is a case-sensitive language; firstName is NOT the same as firstname
  • Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on
  • JavaScript variables must begin with a letter, $, or _
  • JavaScript variables are case sensitive (x is not the same as X)

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.