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

1.2k Views Asked by At

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("-");
4

There are 4 best solutions below

0
On BEST ANSWER

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

0
On

You can use in angular moment js please read moment js implementation. or you can follow this link both question are something same .

[format date with moment.js

1
On

In your html file use this

<input kendo-date-picker
    k-format="'dd/MM/yyyy'"
    ng-model="model.Date"
    name="Date" required />
1
On
var date = new Date('12/20/2018 1:30 AM')
date.toISOString().replace('T', ' ').substring(2, 11) + date.toTimeString().substring(0, 8) // "18-12-19 01:30:00"