Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.clone is not a function

I'm trying to get the start date of a day and the end date. Now to do this I've written this code:

var date_start_temp = $('#calendar').fullCalendar('getView').start;
console.log(date_start_temp)
var date_start = date_start_temp.clone().utc().format("ddd MMM DD YYYY HH:mm:ss");
var date_end = date_start.clone().startOf('day').add(1, 'day').format("ddd MMM DD YYYY HH:mm:ss");

The console.log returns this:

Tue Nov 10 2015 01:00:00 GMT+0100 (ora solare Europa occidentale)

but in the next line I get this error:

date_start_temp.clone(...).utc is not a function

and I don't know why. I just want to get this final result:

date_start

Tue Nov 10 2015 00:00:00

date_end

Wed Nov 11 2015 00:00:00

How you can see I've set the hours to 0 and remove the GMT, I don't want the GMT. How I can achieve this??

like image 877
Dillinger Avatar asked Mar 14 '23 05:03

Dillinger


1 Answers

but in the next line I get this error [...] and I don't know why.

.clone is a method of Moment.js. .start doesn't seem to return a Moment.js instance, so you cannot call .clone on it.

Pass the value to moment first:

var date_start = moment(date_start_temp).utc().format("ddd MMM DD YYYY HH:mm:ss");
like image 158
Felix Kling Avatar answered Mar 23 '23 10:03

Felix Kling