How does one convert a string of a date without a year to a JS Date object? And how does one convert a date string with a year and a time into a JS Date object?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Many different date formats can be converted to date objects just by passing them to the
Date()constructor:Your example date doesn’t work for two reasons. First, it doesn’t have a year. Second, there needs to be a space before “pm” (I’m not sure why).
If the date formats you’re receiving are consistent, you can fix them up this way: