Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  51] [ 6]  / answers: 1 / hits: 5921  / 4 Years ago, tue, december 31, 2019, 12:00:00

I'm trying to update dates in my angular 6 application using Intl.DateTimeFormat and passing locale and dateStyle, timeStyle options. I'm able to get the custom date while trying in browser console however as soon as I try to integrate the same in my app, it throws compilation error: Type '{ dateStyle: string; timeStyle: string; }' has no properties in common with type 'DateTimeFormatOptions'.



    transformDate() {
const options = { dateStyle: full, timeStyle: medium };
console.log(new Intl.DateTimeFormat('en-US',options).format(this.date));
}

More From » html

 Answers
20

It is the datatype issue. You need specify the data type for options.



You can try like -



 const options: any = { dateStyle: full, timeStyle: medium };


Basically Intl.DateTimeFormat accepts options of type DateTimeFormatOptions,
and it has the properties



interface DateTimeFormatOptions {
localeMatcher?: string;
weekday?: string;
era?: string;
year?: string;
month?: string;
day?: string;
hour?: string;
minute?: string;
second?: string;
timeZoneName?: string;
formatMatcher?: string;
hour12?: boolean;
timeZone?: string;
}


Since dateStyle and timeStyle not available , it is throwing an error.


[#5204] Thursday, December 26, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Wed, Dec 11, 19, 00:00, 5 Years ago
;