Date.js:Date.now()行为奇怪 [英] Date.js: Date.now() behaving oddly

查看:743
本文介绍了Date.js:Date.now()行为奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 date.js.

time_container.innerHTML = Date.now()。toString('T'); 工作正常,简要地说,现在在Firebug控制台中抛出错误: code> radix必须是至少为2且不大于36的整数,。

The line time_container.innerHTML = Date.now().toString('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.

注意:date.js toString()函数使用特殊的格式说明符

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 = Date.today().toString('dS of MMMM yyyy');
        }
        if (time_container) {
            //time_container.innerHTML = Date.now().toString('T');
            var d1 = new Date();
            time_container.innerHTML = d1.toString('T');
        }
    }
}
app.onload(show_date.setup);

app.get()只是一个 document.getElementById()的快捷方式。 app.onload()是(正如你可能猜到的)一个onload函数。

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

注释行导致问题。评论下方的替换行工作,但不要给出我想要的格式。 T 应输出 h:mm:ss tt (小时,分钟,秒,上午/下午)。 am / pm位缺失。

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.

另外,我确定 Date.now()今天。也许我会尝试玩电脑时钟,看看是否有所作为。

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

包含的date.js的版本是 date-en- IE.js 。代码中的声明日期是2008-05-13,即使我从今天早些时候从SVN结帐中得到了。

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已经有一个 Date.now()函数返回从1970年1月1日以来的毫秒数。你显然调用该版本,所以 toString('T')调用是在一个数字上,而不是 Date 对象。 Number.prototype.toString 只能从2到36的数字作为参数,这是错误来自哪里。

ECMAScript 5 already has a Date.now() 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.

在查看一下之后,看起来最新的Datejs版本不再添加自己的 Date.now()函数。也许你使用的是旧版本?

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

尝试 new Date()。toString('T')而不是以任何方式工作。

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

这篇关于Date.js:Date.now()行为奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆