← Back to team overview

ubuntu-phone team mailing list archive

Re: [qml] Importing moment.js

 

Hi Sam,

On Fri, Nov 22, 2013 at 1:05 PM, Sam Bull <sam.hacking@xxxxxxxx> wrote:

> Does nobody have any idea how to get a Javascript library working in
> QML? Or, any other ideas how to handle good date formatting? I would
> expect this to be quite important in several of the core apps and other
> parts of Ubuntu Touch.
>

I import javascript libraries in the Clock app. The way I import is by *import
"../common/Utils.js" as Utils*. Then I would use the Utils library
functions by something like Utils.function1(). Hope this helps. Although
you have to note that the QML Javascript engine does not support all of
javascript functions. So when you downloaded "moment.js", you need to make
sure that it works properly in QML. As far as the Date formatting is
concerned, I think the calendar devs should be able to help you with this.

In the clock app, I use the Date() object to do the time and date handling.
Something like,

var now = new Date()

should give you current date and time. You can output it by,

Qt.formatTime(new Date(), "hh:mm")

Hope this helps.

Cheers,
nekhelesh

References