使用Moment模块时出现问题

问题描述:

这是我遇到的一些解析云代码:

Here is some Parse cloud code I am having problem with:

var moment = require('moment');

Parse.Cloud.define
("myCloudFunction", function(request, response)
 {
    var now = moment();
    var later = moment("2017-07-09T20:00:00");
    var x = 7;
    if (later.isAfter(now)) x = x-1;
    else x = x+1;
    console.log(x);
 });

运行该错误消息:

Error: TypeError: Object Sun Jul 09 2017 20:00:00 GMT+0000 (UTC) has no method 'isAfter' at main.js:406:12 (Code: 141, Version: 1.2.18)

我当然简化了问题.

我在做什么错了?

Cloud Code使用的moment.js文件的托管版本停留在1.7.2版本,isAfter方法为2.0 +.

The hosted version of moment.js file used by Cloud Code is stuck at version 1.7.2 and the isAfter method is 2.0+.

下载moment.js的新副本并将其放在您的云/文件夹中,然后按如下所示进行操作:

Download a new copy of moment.js and put it in your cloud/ folder, then require it like this:

var moment = require('cloud/moment.js');