0

I need help in modifying the date output to only be day name, month, day, year for a button output, instead of the full format. How do I shorten it? Here is what I have:

<h2 id="psu1">Spooky Candles</h2>
<button onclick="getElementById('psu1').innerHTML=Date()">
  How soon can I get some delivered?
</button>
technophyle
  • 7,972
  • 6
  • 29
  • 50
  • 8
    Does this answer your question? [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – over-engineer Nov 25 '20 at 20:44

1 Answers1

0

You can try

<h2 id="psu1">Spooky Candles</h2>
<button onclick="getElementById('psu1').innerHTML=new Date().toLocaleDateString('en-US')">
  How soon can I get some delivered?
</button>

You can find more information here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

Abraham Chan
  • 101
  • 3
  • Thank you, that is perfect. I see now where I was going wrong when I tried it myself. I was adding the .toLocaleDateString after 'Date" without the (). Thanks for your help. – Phubbert Nov 25 '20 at 21:44