I have a form on a website where the user will be typing in a date (and time) in the format mm/dd/yyyy hh:mm:ss am (or pm), and I need to convert that to mm-dd-YY hh24:mi:ss However, I've never done any string parsing with javascript before, or converting 24-hour to 12 with am/pm.
Add a comment
|
3 Answers
I would consider using momentjs.
Or use a regular expression to parse it as @Frits van Campen suggested.
1 Comment
Saurabh Chavan
Yes, moment is best
You can also use simple javascript date formatter for date formatting.
And another way is, you can split the Date object to get month,year,day etc values and then create expected format. For that you can refer jsref_obj_date