最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react-intl - FormattedDate - DDMMYYYY instead of MMDDYYYY (for en-us!) - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 3

So, if the locale of your application is working fine, you can just use the FormattedDate ponent from react-intland 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);
发布评论

评论列表(0)

  1. 暂无评论