3

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"

8
  • 3
    There is no built in Date formatting in jQuery. momentjs.com Commented Oct 31, 2015 at 15:05
  • You can use moment.js: momentjs.com/docs/#/displaying Commented Oct 31, 2015 at 15:12
  • you can also check this stackoverflow.com/questions/1531093/… Commented Oct 31, 2015 at 15:17
  • I am not really sure how to implement moments.js, Commented Oct 31, 2015 at 15:19
  • Would it be impossible for me to learn to do this in PHP if its so easy? Commented Oct 31, 2015 at 15:20

3 Answers 3

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());

Sign up to request clarification or add additional context in comments.

1 Comment

She ask for Thursday, October 31, 2015 not 31/09/2015 and the current date is 31/10/2015 =)
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

1 Comment

Amazing!! beautiful ty Alex
1

To get Sat Oct 31 2015 use this:

var TodaysDate = new Date().toDateString();

JsFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.