Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the full date with javascript?

I am trying to get the full date with my function. Right now my results are "Wed Feb 14 2018", but I would like it to say "Wednesday February 2018". I want it to say the whole day and whole month. I could not find a "get fullDate" method unfortunately..

window.onload = function() {
  var date = new Date();

  document.getElementById("date").innerHTML = date.toDateString();
}
<div id="date"> </div>
like image 442
Alison Avatar asked Oct 22 '25 12:10

Alison


1 Answers

You're actually looking for the toLocaleString function, as it can be customized pretty heavily without losing your date object.

window.onload = function() {
  var date = new Date();

  document.getElementById("date").innerHTML = date.toLocaleString('en-US', {weekday: 'long', month: 'long', year: 'numeric'});
}
<div id="date"> </div>
like image 109
John Pavek Avatar answered Oct 25 '25 00:10

John Pavek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!