Forging Titanium Episode 12: Titanium & Date.js

0 Flares 0 Flares ×

To keep the ball rolling on integrating existing Javascript libraries with Titanium, this week’s episode shows off the Date.js library in a cross-platform mobile app. We’ll include this powerful date and time processing library, in a modular manner, to enhance the native Javascript Date object. Ideally, you’ll let Date.js do all the grunt work of parsing disparately formatted dates while you spend your valuable time adding much more interesting features to your Titanium apps.

Episode Highlights

  • Introduction to the Date.js workhorse function, Date.parse()
  • Including existing Javascript libraries with CommonJS, even when they don’t export a module
  • Using the Titanium.UI.Picker to display a native picker component as each platform’s users would expect

Episode Resources:

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×


  1. Thanks for another great tutorial.
    Unfortunately date.js hasn’t been updated in over 4-5 years.

  2. @Serge: Typically I would see that as a bad thing as well, but the needs of date formatting have not changed dramatically over that period of time. The library built a rock solid core on its improved date parsing and provided a _ton_ of functions to modify, display, and compare.

    I guess the question is, what do you think is missing from Date.js?

  3. Canastro

    I tried Datejs and in debug mode I get tons of breakpoints date.js when I do require of that js file…

  4. twelve dogs

    you really need to download date.js out of it’s subversion repo if you want a working version as i found some weirdness with just putting “12am” into the parse function until i got the very latest check in.

  5. Dave

    When I TI.Include date.js, and run the simulator in debug mode, I get uncaught exceptions here:

    rtoken: function (r) { // regex token
    return function (s) {
    var mx = s.match(r);
    if (mx) {
    return ([ mx[0], s.substring(mx[0].length) ]);
    } else {
    throw new $P.Exception(s); // <– Exception Here

    Not sure why, since two levels up the stack, there is a catch(e) clause. This doesn't happen in a pure web project. is it a Titanium bug?

  6. Kyle

    I also get the same behavior as Dave when running in debug mode. Any suggestions?

  7. Andrew

    I’ve installed the app on my Android device, but it errors all the time at:

    Location: [113,21] app.js
    Message: “Uncaught RangeError: toString() radix arguement must be between 2 and 36”
    Source: label.text = date.toString(‘dddd.MMMM dd,yyyy h:mm:ss tt’);

    Do you have a working version or any ideas for what might be wrong?

  8. @Andrew

    I was having this problem untill I used Ti.include instead or require.


  9. Better option.

    It is uptodate and maintained. I had lots of problems with datejs. Including different versions called the same thing and an inability to parse their own iso date strings. I’ve had no issues with momentjs. Simply require it:

    var moment = require(‘/lib/thirdParty/moment.min’);

    • Vishal

      Matt Bourne,
      Thank you for the link.

Comments are closed.

Sign up for our blog!

computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×