加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

处理angular2关于date格式化浏览器不兼容的问题

发布时间:2020-12-17 09:09:05 所属栏目:安全 来源:网络整理
导读:在使用angular2的过程中使用自带时间格式化pipe会在Safari浏览器报错,针对这一问题,我们可以参考下属代码,自定义格式化pipe import {PipeTransform,Pipe} from "@angular/core";var moment = require('moment/moment.js');@Pipe({name: "custime"})export
在使用angular2的过程中使用自带时间格式化pipe会在Safari浏览器报错,针对这一问题,我们可以参考下属代码,自定义格式化pipe
import {PipeTransform,Pipe} from "@angular/core";
var moment = require('moment/moment.js');

@Pipe({name: "custime"})
export class TimePipe implements PipeTransform {

    /**
     * 格式化时间字符串
     *
     * @param value 时间字符串
     * @param args 要格式话成的格式
     * @returns {any}
     */
    transform(value: any,args: any): any {
        return moment(value).format(args.toUpperCase());
    }
}
在上述代码中我们引用了专门操作时间类信息工具moment.js

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读