If I have a this date: April 14, 2022 14:00 UTC
, how I can validate that it is in MMMM DD, YYYY HH:mm <timezone>
?
I tried it with moment
but it doesn't have format for timezone.
moment(date, 'MMMM DD, YYYY HH:mm',true).isValid()
How can I validate that the string is in MMMM DD, YYYY HH:mm <timezone>
format?
You can include " UTC" as literal text in the parse format, e.g.
Per the moment.js documentation, various offset formats are supported, so if there are other offset representations you can use multiple tests to support say "UTC" and "+00:00" (or ±HH:mm in general), e.g.
Unfortunately isValid doesn't support multiple formats in the one call so you can't do:
as only the first format is recognised.