Angularjs中date过滤器失效的问题及解决方法
- 作者: 逝去的快乐呢
- 来源: 51数据库
- 2021-07-10
在开发中遇到date过滤器失效的问题,在其他页面date过滤器没有问题,但是在这个页面出现了问题,后来发现是因为{{now | date : 'yyyy-mm-dd hh:mm:ss'}}
now必须是时间戳格式的,后面的过滤器才会生效。而我从后端传过来的时间数据是字符串所以过滤器无法生效
解决方法:在后端处理要传的数据,将里面的时间转为时间戳即可(下面贴我百度到的)
/** * 时间转时间戳 */ public static string datetostamp(string s) throws parseexception{ string res; simpledateformat simpledateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss"); date date = simpledateformat.parse(s); long ts = date.gettime(); res = string.valueof(ts); return res; }
总结
以上所述是小编给大家介绍的angularjs中date过滤器失效的问题及解决方法,希望对大家有所帮助
推荐阅读
热点文章
Angular中响应式表单的三种更新值方法详析
7
Angularjs实现下拉框联动的示例代码
7
详解AngularJS跨页面传值(ui-router)
2
详解AngularJS1.x学习directive 中‘& ’‘=’ ‘@’符号的区别使用
3
angular2路由切换改变页面title的示例代码
4
Angular2 组件间通过@Input @Output通讯示例
5
Angularjs中ng-repeat的简单实例
3
AngularJS 中ui-view传参的实例详解
4
浅谈Angular路由守卫
4
详解基于Angular4+ server render(服务端渲染)开发教程
4