Date.js: behaving oddly

I'm using date.js.

The line time_container.innerHTML ='T'); worked fine, briefly, and is now throwing errors in the Firebug console: radix must be an integer at least 2 and no greater than 36. It was certainly working earlier.

Note: The date.js toString() function uses special format specifiers.

var show_date = {
    setup: function() {
        setInterval(show_date.update, 5000);
    update: function() {
        var date_container = app.get('js_date');
        var time_container = app.get('js_time');

        if (date_container) {
            date_container.innerHTML ='dS of MMMM yyyy');
        if (time_container) {
            //time_container.innerHTML ='T');
            var d1 = new Date();
            time_container.innerHTML = d1.toString('T');

app.get() is just a shortcut for document.getElementById(). app.onload() is (as you might guess) an onload function.

Commented out line is causing the problems. Replacement lines below the comment work, but don't give the format I want. T should output h:mm:ss tt (hours, minutes, seconds, am/pm). The am/pm bit is missing.

Also, I'm certain was working earlier today. Perhaps I'll try playing with the computer clock to see whether that makes a difference.

Version of date.js included is date-en-IE.js. Claimed date in the code is 2008-05-13, even though I got it from the SVN checkout earlier today.



ECMAScript 5 already has a function that returns the number of milliseconds since January 1, 1970. You're apparently calling that version so the toString('T') call is on a number, not a Date object. Number.prototype.toString can only take a number from 2 to 36 as its argument, which is where the error is coming from.

After looking into it a little, it looks like the latest Datejs version doesn't add its own function anymore. Maybe you were using an older version when it worked?

Try new Date().toString('T') instead, which should work either way.


I had a same error in FireFox. By changing .toString() method to .toDateString() seems like took care of that problem. Example:'M/d/yyyy HH:mm')


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.