Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current date in javascript

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"

like image 831
jogx Avatar asked Aug 27 '26 21:08

jogx


1 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());
like image 101
Sky Voyager Avatar answered Aug 30 '26 12:08

Sky Voyager



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!