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)); // शनिवार, 17 सितंबर 2016
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
6
7 // For custom format use
8 date.toLocaleDateString("en-US", { day: 'numeric' })+ "-"+ date.toLocaleDateString("en-US", { month: 'short' })+ "-" + date.toLocaleDateString("en-US", { year: 'numeric' }) // 16-Nov-2019
9
1const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
2
3const options = { year: 'numeric', month: 'short', day: 'numeric' };
4
5console.log(event.toLocaleDateString('de-DE', options));
6// expected output: Donnerstag, 20. Dezember 2012
7
8console.log(event.toLocaleDateString('en-US', options));
9// US format
10
11
12// In case you only want the month
13console.log(event.toLocaleDateString(undefined, { month: 'short'}));
14console.log(event.toLocaleDateString(undefined, { month: 'long'}));
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 dateStr = '2020-06-21T10:15:00Z',
2
3 [yyyy,mm,dd,hh,mi] = dateStr.split(/[/:\-T]/)
4
5console.log(`${dd}-${mm}-${yyyy} ${hh}:${mi}`)