【问题标题】:Converting mysql date to js date works in chrome but not safari将 mysql 日期转换为 js 日期在 chrome 中有效,但在 safari 中无效
【发布时间】:2016-09-26 18:51:32
【问题描述】:

我在 angular2 中使用管道将 mysql 日期转换为 js 日期格式,这是我的代码:

export class DateToIso {
    transform(value) {
        let date = new Date(value);
        let str = (date.getMonth() + 1) + '.' + date.getDate() + '.' +  date.getFullYear()
        return str;
    }
}

在 HTML 中我使用 {{ post[2] | dateToIso}} 显示转换后的日期。在 Chrome 中,我得到了正确的日期时间,但在 safari 中却没有。它返回NaN.NaN.NaN

【问题讨论】:

标签: mysql angular ionic2


【解决方案1】:

我在货币管道上遇到了类似的问题,这是一个国际化问题。我写在这里http://blogs.msmvps.com/deborahk/angular-2-getting-started-problem-solver/

  1. 安装国际包:npm install intl@1.1.0 –save

  2. 在 index.html 中包含以下内容:

(我使用的是触控设备,粘贴的代码不起作用,请看链接)

【讨论】:

    【解决方案2】:

    我尝试了@DeborahK,但它没有用,所以我只取了 Mysql 日期“字符串”并从中制作子字符串,并将子字符串重新排列为一个新字符串并返回它。

    export class DateToIso {
        transform(value, args) {
            let month = value.substr(5,2);
            let day = value.substr(8,2);
            let timeThen = value.substr(11,5);
            let newValue = day + "." + month + " um " + timeThen;
            return newValue;
        }
    }
    

    我相信这不是最好的解决方案,但它确实有效。希望尽快得到更好的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      相关资源
      最近更新 更多