Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date using javascript in this format [MM/DD/YY]


how can I get the date in this format [mm/dd/yy] using javascript. I am struggling to get the 'year' to a 2 digit figure as opposed to the full 4 digits.

Thanks!

like image 924
user1779796 Avatar asked Nov 01 '12 19:11

user1779796


1 Answers

var date = new Date();
var datestring = ("0" + (date.getMonth() + 1).toString()).substr(-2) + "/" + ("0" + date.getDate().toString()).substr(-2)  + "/" + (date.getFullYear().toString()).substr(2);

This guarantees 2 digit dates and months.

like image 98
Asad Saeeduddin Avatar answered Sep 19 '22 20:09

Asad Saeeduddin