string to date angular 1

string to date angular

  
let dateString = '02/05/2020';  
let momentVariable = moment(dateString, 'MM-DD-YYYY');  
let stringvalue = momentVariable.format('YYYY-MM-DD');   
console.log(stringvalue); // outputs 2020-05-02  

Here is what the above code is Doing:
1. We are creating a moment object using the moment() function.
2. We are passing the date string and the format of the date string to the moment() function.
3. We are using the format() function to convert the moment object to a string.
4. We are passing the format of the string to the format() function.
5. We are printing the string to the console.

Similar Posts