Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Unicode Tokens
  2. Starting with v2 `format` and `parse` uses [Unicode tokens].
  3. The tokens are different from Moment.js and other libraries that opted to use
  4. custom formatting rules. While usage of a standard ensures compatibility and
  5. the future of the library it causes confusion that this document intended
  6. to resolve.
  7. ## Popular mistakes
  8. There are 4 tokens that causes the most of confusion:
  9. - `D` and `DD` that represent the day of a year (1, 2, ..., 365, 366)
  10. are often confused with `d` and `dd` that represent the day of a month
  11. (1, 2, ..., 31).
  12. - `YY` and `YYYY` that represent the local week-numbering year (44, 01, 00, 17)
  13. are often confused with `yy` and `yyyy` that represent the the calendar year.
  14. ```js
  15. // ❌ Wrong!
  16. format(new Date(), 'YYYY-MM-DD')
  17. //=> 2018-10-283
  18. // ✅ Correct
  19. format(new Date(), 'yyyy-MM-dd')
  20. //=> 2018-10-10
  21. // ❌ Wrong!
  22. parse('11.02.87', 'D.MM.YY', new Date()).toString()
  23. //=> 'Sat Jan 11 1986 00:00:00 GMT+0200 (EET)'
  24. // ✅ Correct
  25. parse('11.02.87', 'd.MM.yy', new Date()).toString()
  26. //=> 'Wed Feb 11 1987 00:00:00 GMT+0200 (EET)'
  27. ```
  28. To help with the issue, `format` and `parse` functions won't accept
  29. these tokens without `useAdditionalDayOfYearTokens` option for `D` and `DD` and
  30. `useAdditionalWeekYearTokens` options for `YY` and `YYYY`:
  31. ```js
  32. format(new Date(), 'D', { useAdditionalDayOfYearTokens: true })
  33. //=> '283'
  34. parse('365+1987', 'DD+YYYY', new Date(), {
  35. useAdditionalDayOfYearTokens: true,
  36. useAdditionalWeekYearTokens: true
  37. }).toString()
  38. //=> 'Wed Dec 31 1986 00:00:00 GMT+0200 (EET)'
  39. ```
  40. [Unicode tokens]: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table