How would I get the current date to display in jquery as "Saturday, October 31, 2015"? I can only find how to get the date to display as "dd/mm/yyyy"
Asked
Active
Viewed 112 times
3
-
3There is no built in Date formatting in jQuery. http://momentjs.com/ – Alex K. Oct 31 '15 at 15:05
-
You can use moment.js: http://momentjs.com/docs/#/displaying/ – Alexander Elgin Oct 31 '15 at 15:12
-
you can also check this http://stackoverflow.com/questions/1531093/how-to-get-current-date-in-javascript – Maduro Oct 31 '15 at 15:17
-
I am not really sure how to implement moments.js, – jogx Oct 31 '15 at 15:19
-
Would it be impossible for me to learn to do this in PHP if its so easy? – jogx Oct 31 '15 at 15:20
-
`$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001 ` – Maduro Oct 31 '15 at 15:31
-
http://php.net/manual/en/function.date.php you can check this link too – Maduro Oct 31 '15 at 15:33
-
[Where can I find documentation on formatting a date in JavaScript?](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Jonathan Lonowski Oct 31 '15 at 16:02
3 Answers
2
To get 31/10/2015 use this :
// "31/10/2015" and august : 31/08/2015 :
var a=new Date();
alert([("0" + a.getDate()).slice(-2), ("0" + (a.getMonth()+1)).slice(-2), a.getFullYear()].join("/"));
// "31/10/2015" and august : 31/8/2015 :
[a.getDate(), (a.getMonth() + 1), a.getFullYear()].join("/");
Example :
function getDate() {
var a=new Date();
return [("0" + a.getDate()).slice(-2), ("0" + (a.getMonth() + 1)).slice(-2), a.getFullYear()].join("/");
}
document.write(getDate());

user2226755
- 12,494
- 5
- 50
- 73
-
3She ask for `Thursday, October 31, 2015` not `31/09/2015` and the current date is `31/10/2015` =) – Maduro Oct 31 '15 at 15:27
1
You can:
var date = new Date();
var str = ["Sunday", "mon", "tues", "wed", "thurs", "fri", "sat", "sun"][date.getDay()];
str += ", " + ["jan", "feb", "mar", "apr", "may", "june", "jul", "aug", "sep", "oct", "November", "dec"][date.getMonth()];
str += " " + date.getDate();
str += ", " + date.getFullYear();
console.log(str);
Sunday, November 1, 2015

Alex K.
- 171,639
- 30
- 264
- 288