1var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
2var today = new Date();
3
4console.log(today.toLocaleDateString("en-US")); // 9/17/2016
5console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
6console.log(today.toLocaleDateString("hi-IN", options));
1function formatDate(date) {
2 var hours = date.getHours();
3 var minutes = date.getMinutes();
4 var ampm = hours >= 12 ? "PM" : "AM";
5 hours = hours % 12;
6 hours = hours ? hours : 12; // the hour "0" should be "12"
7 minutes = minutes < 10 ? "0" + minutes : minutes;
8 var strTime = hours + ":" + minutes + " " + ampm;
9 return date.getDate() + "/" + new Intl.DateTimeFormat('en', { month: 'short' }).format(date) + "/" + date.getFullYear() + " " + strTime;
10}
11
12var d = new Date();
13var e = formatDate(d);
14
15console.log(e); // example output: 11/Feb/2021 1:23 PM
1const d = new Date.now;
2const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d);
3const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d);
4const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d);
5console.log(`${da}-${mo}-${ye}`);
1<p>The toDateString() method converts a date to a date string:</p>
2
3<p id="demo"></p>
4
5<script>
6var d = new Date();
7document.getElementById("demo").innerHTML = d.toDateString();
8</script>
9//output: Fri Oct 16 2020