'Easy way to parse "February 03, 2022 at 04:52PM" into Date in Javascript
Apologies, I'm a noob with Javascript and I couldn't see any easy way to parse February 03, 2022 at 04:52PM into a Date object.
The best I can think of is using Regex to split each part of the string into it's own component and then create a new Date object. But I'll need a switch statement to parse the month also.
I need to do this in plain JS, no libraries.
Solution 1:[1]
Well with moment.js you can parse your string as it is and define the formatting. Head over to the librarys' page and open the dev console to play with it!
basically you do want to do this:
const date = moment('February 03, 2022 at 04:52PM', 'MMMM DD, YYYY at hh:mm A')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | moeses |
