How do I parse localized date/time strings? #1617
Unanswered
willytrigg
asked this question in
Q&A
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am working on replacing Moment.js. One use case I have to replace is the parsing and validating of user-inputted dates in their browser's locale. For instance, the string '01/02/2024' should be interpreted as January 2, 2024 if the user has 'en' as their language or as February 1, 2024 in certain other locales. I believe there is another locale that has periods between the date units as well, so it should look for a string in the format '01.02.2024'.
The problem I have is that the 'fromFormat()' function takes in an exact format string/token rather than a localized one. For instance, it will interpret 'MM/dd/yyyy' as an exact format rather than a format that changes to suit the current locale. It appears that this library does have localized format strings/tokens, but they are only available for formatting, not parsing.
Is there a way to get a localized parsing format dynamically? It is not possible for me to define a different format string for every locale that the browser supports, so I am not sure how to implement multi-language parsing.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions