I want the Date format as MM/DD/YYYY and I am using Intl.DateTimeFormat
console.log(new Intl.DateTimeFormat('en-US').format(date));
output: "6/20/2012"
The output I need is "06/20/2012"
What change should I do to get the expected result?
I want the Date format as MM/DD/YYYY and I am using Intl.DateTimeFormat
console.log(new Intl.DateTimeFormat('en-US').format(date));
output: "6/20/2012"
The output I need is "06/20/2012"
What change should I do to get the expected result?
Share Improve this question asked Jun 26, 2020 at 8:39 Jane FredJane Fred 1,4898 gold badges26 silver badges49 bronze badges2 Answers
Reset to default 20Provide the options object:
console.log(new Intl.DateTimeFormat('en-US',{month:'2-digit',day:'2-digit', year:'numeric'}).format(new Date()));
Helpful Cheatsheet
Available Options:
{
weekday: 'narrow' | 'short' | 'long',
era: 'narrow' | 'short' | 'long',
year: 'numeric' | '2-digit',
month: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long',
day: 'numeric' | '2-digit',
hour: 'numeric' | '2-digit',
minute: 'numeric' | '2-digit',
second: 'numeric' | '2-digit',
timeZoneName: 'short' | 'long',
// Time zone to express it in
timeZone: 'Asia/Shanghai',
// Force 12-hour or 24-hour
hour12: true | false,
// Rarely-used options
hourCycle: 'h11' | 'h12' | 'h23' | 'h24',
formatMatcher: 'basic' | 'best fit'
}
let today = new Date().toISOString().split('T')[0];