Moment.js in QML

I am looking for a way to format dates beautifully. It looks like moment.js will give me what I want, but I can’t figure out how to use it from a QML or Javascript file (this is for Ubuntu Touch).

I downloaded the c-langs file from the website (and renamed it to "moment.js"), and then tried "import" moment.js "as a moment" and "Qt.include (" moment.js ")", but still seems unable to use it.

Any ideas on how to make this work?

+4
source share
1 answer

I tried this on my machine and it seems like I found a problem. QML gives me a parsing error. Indeed, in the fragment

(function () {
  extend(null, {
    gett : function (units) {
        return null;
    },

    as : function (units) {
    }
  });
})();

It cannot parse the code around asbecause it asis a keyword in QML and is not in javascript. Thus, it seems that sometimes you cannot use javascript libraries "as is".

To fix the problem, we can add quotes around as: "as".

0
source

All Articles