日期格式在Firefox和IE中呈现不同的结果

时间:2015-09-15 19:57:07

标签: javascript datetime date-format date-formatting

我正在尝试渲染日期,但结果在firefox和IE中有所不同。输出是:

2015年7月21日下午3:13 - Firefox

2015年7月21日星期二下午3:13:10 - IE

如何让IE不显示日期和秒数?

我的代码是(让我们说dateVal是1440671523862):

    function csDateFormatProvider(evalFilter) {
    return function (dateVal, type, message) {
        var options = {
                month : "long",
                day : "numeric",
                year : "numeric"
            },
            localDate = new Date(),
            adjustedDataDate = new Date(dateVal),
            localeTime = adjustedDataDate.toLocaleTimeString(csConfig.LOCALE, {hour: '2-digit', minute:'2-digit'}),
            localeDate = adjustedDataDate.toLocaleDateString(csConfig.LOCALE, options);

        if (type === "date") {
            return adjustedDataDate.toLocaleDateString(csConfig.LOCALE, options);
        } else if (type === "date-time") {
            if (localDate.getFullYear() === adjustedDataDate.getFullYear() &&
                    localDate.getMonth() === adjustedDataDate.getMonth()) {
            if(localDate.getDate() === adjustedDataDate.getDate()) {
                    return app.evaluate(message, messages.TODAY, localeTime);
                } else if (localDate.getDate() === (adjustedDataDate.getDate() + 1)) {
                    return app.evaluate(message, messages.YESTERDAY, localeTime);
                }
            }
            return app.evaluate(message, localeDate, localeTime);
        } else {
            return app.evaluate(message, localeDate, localeTime);
        }
    }
};

0 个答案:

没有答案
相关问题