本文介绍了AngularJS 如何转换字符串“yyyyMMdd"迄今为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮忙在下面的Angularjs中转换吗我有值20141023",想在 AngularJS 中转换为日期,然后以 dd/MMM/yyyy 格式显示视图非常感谢N.

解决方案

可以使用正则表达式请看下面的demo

var app = angular.module('app', []);app.controller('homeCtrl', function($scope) {var st = "20130510";var 模式 =/(\d{4})(\d{2})(\d{2})/;$scope.date = new Date(st.replace(pattern, '$1-$2-$3'));});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><div ng-app="app"><div ng-controller="homeCtrl">{{日期 |日期:'dd/MMM/yyyy'}}

can you help please to convert below in AngularjsI have value "20141023" and would like to convert to date in AngularJS and then displayed View in format dd/MMM/yyyyMany thanksN.

解决方案

You can use regular expression please see demo below

var app = angular.module('app', []);

app.controller('homeCtrl', function($scope) {

  var st = "20130510";
  var pattern = /(\d{4})(\d{2})(\d{2})/;
  $scope.date = new Date(st.replace(pattern, '$1-$2-$3'));

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="app">
  <div ng-controller="homeCtrl">

    {{date | date :'dd/MMM/yyyy'}}
  </div>
</div>

这篇关于AngularJS 如何转换字符串“yyyyMMdd"迄今为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:31