How can I get the current date in JQuery as a variable and then append to a heading in with an id of currentdate
, with the format 24th July 2016
?
Asked
Active
Viewed 1,720 times
-3

Mohammad
- 21,175
- 15
- 55
- 84

Kyler Phillips
- 41
- 10
2 Answers
0
In XClass library , just do :
new Date().format('ddS mmmm yyyy')
- dd : day of month
- S : suffix (st,nd,th,..)
- mmmm: Full name of month
- yyyy : year
DEMO
var out=document.getElementById('out');
out.innerHTML=new Date().format('ddS mmmm yyyy');
<script src="https://rawgit.com/abdennour/xclass/master/node_modules/x-date/index.js"></script>
<span id="out"></span>

Community
- 1
- 1

Abdennour TOUMI
- 87,526
- 38
- 249
- 254
-1
You need to use javascript Date()
object and method of it to getting current date and component of it.
var monthName = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var date = new Date();
var dateStr = date.getDate() + "th " + monthName[date.getMonth()] + " " + date.getFullYear();
$("#currentdate").text(dateStr);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="currentdate"></div>

Mohammad
- 21,175
- 15
- 55
- 84