peter flanagan peter flanagan -3 years ago 97
Javascript Question

change date format javascript

I need to send a date to a backend service that requires a date in the following format.

I have access to moment also.

I am using an input type of

on the front end which sends over a date like this:

I have tried
new Date("2017-05-17T10:00");
but this returns
Wed May 17 2017 11:00:00 GMT+0100 (BST)
. I have also tried using some
methods, but cannot get the correct format.

Does anyone know how I can convert the datetime string -
to the following

Answer Source

Try moment.format(). Here is the list for reference

var dt = new Date("2017-05-17T10:00");


var z = moment(dt).format("YYYY-MM-DDTHH:mm:ssZZ");
<script src=""></script>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download