Difference between revisions of "DOM Calendar"

From ProgZoo
Jump to navigation Jump to search
Line 2: Line 2:
==Display dates as specified==
==Display dates as specified==
<div class=qu data-width=300>
<div class=qu data-width=300>
The phrase:
let today = new Date()
sets the variable <code>today</code> to today's date
*For today's date show
*For today's date show
**day of the week in English
**day of the week in English
Line 10: Line 7:
**day of the week in French
**day of the week in French
**month in French
**month in French
The phrase:
let today = new Date()
sets the variable <code>today</code> to today's date
The function toLocalDateString takes an ''options'' object. You can set:
The function toLocalDateString takes an ''options'' object. You can set:
*weekday to <code>long</code> <code>short</code> <code>narrow</code>  
*weekday to <code>long</code> <code>short</code> <code>narrow</code>  

Revision as of 21:39, 9 January 2022


Display dates as specified

  • For today's date show
    • day of the week in English
    • month in English
    • day of the week in French
    • month in French

The phrase:

let today = new Date()

sets the variable today to today's date The function toLocalDateString takes an options object. You can set:

  • weekday to long short narrow
  • month to long short narrow
  • the first parameter can be a language such as "en", "fr", "de", "zh"
let today = new Date();
document.body.innerHTML = `
${today.toLocaleDateString('en',{weekday:'long'})} <br>
${today.toLocaleDateString('en',{weekday:'short'})} <br>
`;
let today = new Date();
document.body.innerHTML = `
${today.toLocaleDateString('en',{weekday:'long'})} <br>
${today.toLocaleDateString('en',{month:'long'})} <br>
${today.toLocaleDateString('fr',{weekday:'long'})} <br>
${today.toLocaleDateString('fr',{month:'long'})} <br>
`;