javascript .clone 不是一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33638160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.clone is not a function
提问by Dillinger
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:
console.log 返回这个:
Tue Nov 10 2015 01:00:00 GMT+0100 (ora solare Europa occidentale)
2015 年 11 月 10 日星期二 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
date_start_temp.clone(...).utc 不是函数
and I don't know why. I just want to get this final result:
我不知道为什么。我只想得到这个最终结果:
date_start
日期_开始
Tue Nov 10 2015 00:00:00
2015 年 11 月 10 日星期二 00:00:00
date_end
日期_结束
Wed Nov 11 2015 00:00:00
2015 年 11 月 11 日星期三 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??
你怎么看我已经将小时数设置为 0 并删除了 GMT,我不想要 GMT。我怎么能做到这一点?
回答by Felix Kling
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.
.clone
是 Moment.js 的一个方法。.start
似乎没有返回 Moment.js 实例,所以你不能调用.clone
它。
Pass the value to moment
first:
将值传递给moment
第一个:
var date_start = moment(date_start_temp).utc().format("ddd MMM DD YYYY HH:mm:ss");