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));
1const t = new Date();
2const date = ('0' + t.getDate()).slice(-2);
3const month = ('0' + (t.getMonth() + 1)).slice(-2);
4const year = t.getFullYear();
5const hours = ('0' + t.getHours()).slice(-2);
6const minutes = ('0' + t.getMinutes()).slice(-2);
7const seconds = ('0' + t.getSeconds()).slice(-2);
8const time = `${date}/${month}/${year}, ${hours}:${minutes}:${seconds}`;
9
10output: "27/04/2020, 12:03:03"
1const formatDate = date => {
2 return (
3 date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
4 );
5};
6
7console.log(formatDate(new Date()));