Search code examples
javascriptangularjskendo-datetimepicker

How to convert "12/20/2018 1:30 AM" format to the YY-MM-DD hh:mm:ss in angular js?


I have to store the date in the database using this format YY-MM-DD hh:mm:ss but I get this 12/20/2018 1:30 AM after select date from the kendo-datetime picker.

I have tried fomat="YY-MM-SS hh:mm:ss" but its not working every time getting above the same format.

Tell me, anyone, how to convert selected date and time to YY-MM-DD hh:mm:ss?

var date = object.dTime;
var newdate = date.split("/").reverse().join("-");

Solution

  • Use moment library in order to format the date into whatever way that you want to display,

    moment(date).format('YY-MM-SS hh:mm:ss')
    

    For more detail, look at here