Reputation: 5939
I have a javascript datetime picker which generated a time in this format: 2017-09-03T11:37:00.000Z
Now, I am trying to set default value of december 31, 2007 but I don't know how to generate it with the format the datepicker uses.
I have done jsfiddle:
var original = '2017-09-03T11:37:00.000Z';
var recreate = moment().endOf('year').format('YYYY-MM-HH:MM-SS:MS');
alert(recreate) // 2017-12-23:12-99:129
but the format isn't the same
Upvotes: 2
Views: 54
Reputation: 24581
This format is known as ISO date format. You can convert moment to this format by calling corresponding function:
var original = '2017-09-03T11:37:00.000Z';
var recreate = moment().endOf('year').toISOString();
alert(recreate)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
See updated fiddle
Upvotes: 3
Reputation: 1503
toDate() to get it in correct format. check this
var original = '2017-09-03T11:37:00.000Z';
var recreate = moment().endOf('year');
alert(moment(recreate).toDate());
Upvotes: 2