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.
            Asked
            
        
        
            Active
            
        
            Viewed 481 times
        
    1
            
            
         
    
    
        Alex Kibler
        
- 4,674
- 9
- 44
- 74
3 Answers
1
            
            
        Use regular expressions to parse the input. If you've never used regular expressions before search for a good tutorial on Google, I'm sure you'll find something.
 
    
    
        Halcyon
        
- 57,230
- 10
- 89
- 128
1
            
            
        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
 
    
    
        Nishu Tayal
        
- 20,106
- 8
- 49
- 101
