0

I am using this code to get the date into a span with id 'today'. However now requirements mean I need to take the actual day of the week out of the line. So just 14 Sep 2018 (for example?) Is there a way to achieve this without spelling out the whole date.

$('#today').html(d.toDateString());
Heretic Monkey
  • 10,498
  • 6
  • 45
  • 102
conye9980
  • 119
  • 8

1 Answers1

2

The toDateString() method returns the date portion of a Date object in human readable form in American English.

You can split the string with empty string then rearrange the string in the way you want:

var d =  new Date().toDateString(); //Fri Sep 14 2018
d = d.split(' ');                   //["Fri","Sep","14","2018"]
$('#today').html(d[2] + ' ' + d[1] + ' ' + d[3]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="today"></span>
Mamun
  • 58,653
  • 9
  • 33
  • 46