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"
-
3There is no built in Date formatting in jQuery. momentjs.comAlex K.– Alex K.2015-10-31 15:05:33 +00:00Commented Oct 31, 2015 at 15:05
-
You can use moment.js: momentjs.com/docs/#/displayingAlexander Elgin– Alexander Elgin2015-10-31 15:12:17 +00:00Commented Oct 31, 2015 at 15:12
-
you can also check this stackoverflow.com/questions/1531093/…Maduro– Maduro2015-10-31 15:17:02 +00:00Commented Oct 31, 2015 at 15:17
-
I am not really sure how to implement moments.js,jogx– jogx2015-10-31 15:19:48 +00:00Commented Oct 31, 2015 at 15:19
-
Would it be impossible for me to learn to do this in PHP if its so easy?jogx– jogx2015-10-31 15:20:25 +00:00Commented Oct 31, 2015 at 15:20
|
Show 3 more comments
3 Answers
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());
1 Comment
Maduro
She ask for
Thursday, October 31, 2015 not 31/09/2015 and the current date is 31/10/2015 =)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
1 Comment
jogx
Amazing!! beautiful ty Alex