sardine sardine - 3 months ago 14
Javascript Question

Javascript new Date() outputs 'YYYY-MM-DD hh:mm:ss' data as UTC although it's not

I have a simple line of code which I need for a date output in a modal, that emerges when you click on an entry in my fullcalendar-script calendar.
It looks like this:

eventClick: function(calEvent, jsEvent, view) {
$('#modalStart').html(new Date(calEvent.start));
$('#modalEnd').html(new Date(calEvent.end));
},


The JSON data that gets interpreted (
start
and
end
) is formatted as
YYYY-MM-DD h:i:s
and i want it to stay like that. But the modal with
new Date
outputs the following:

Start: Tue Aug 02 2016 06:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)

End: Mon Aug 15 2016 08:00:01 GMT+0200 (Mitteleuropäische Sommerzeit)

although it should be

Start: Tue Aug 02 2016 04:00:00

End: Mon Aug 15 2016 06:00:01

I'm sure there is a simple solutio for this. I tried
.html(new Date(date.UTC()))
but that didn't work. I'd be very thankful if someone could help.

Answer

Whatever you're planning to do, this should do the trick:

eventClick: function(calEvent, jsEvent, view) {
            $('#modalStart').html(new Date(calEvent.start).toUTCString()); 
            $('#modalEnd').html(new Date(calEvent.end).toUTCString());
},
Comments