I have an application with react-intl injected. Its bilingual - in English and in Polish so i represent dates with . When I represent let's say 12 April 2005 its:
12.04.2005 in Polish
04/12/2005 in English
It confuses everyone as people think about the second date as 4th December. Can i somehow format dates so in English it would be DD/MM/YYYY ?
I have an application with react-intl injected. Its bilingual - in English and in Polish so i represent dates with . When I represent let's say 12 April 2005 its:
12.04.2005 in Polish
04/12/2005 in English
It confuses everyone as people think about the second date as 4th December. Can i somehow format dates so in English it would be DD/MM/YYYY ?
Share Improve this question asked Jul 2, 2018 at 11:54 marcus-linmarksonmarcus-linmarkson 3734 gold badges15 silver badges39 bronze badges 1- Please note that the format MM/DD/YYYY is used by a minority of English speakers and is peculiar to the USA, not English speakers in general. Far better to use an unambiguos format that uses the month name like DD-MMM-YYYY (e.g. 12-Jul-2018) or MMMM D, YYYY (e.g. July 12, 2018). – RobG Commented Jul 2, 2018 at 14:27
2 Answers
Reset to default 3So, if the locale of your application is working fine, you can just use the FormattedDate ponent from react-intl
and it will display the date in the current format.
Assuming that the locale is in place, you'd only have to use it like this:
<FormattedDate
value="12.04.2005"
day="2-digit"
month="2-digit"
year="numeric"
/>
The FormattedDate ponent will use the locale of the application to format it to english or polish (or any other locale you set). Here is the reference in the doc
There is not much to work with, but see if this helps:
let PolishDate = '12.04.2005';
let arr = PolishDate.split('.');
let EnglishDate = arr[1] + '/' + arr[0] + '/' + arr[2];
console.log(EnglishDate);