AngularJS how to convert string “yyyyMMdd” to date

can you help please to convert below in Angularjs I have value "20141023" and would like to convert to date in AngularJS and then displayed View in format dd/MMM/yyyy Many thanks N.



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})/;
  $ = new Date(st.replace(pattern, '$1-$2-$3'));

<script src=""></script>

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

    {{date | date :'dd/MMM/yyyy'}}


I would suggest using MomentJS (see the basic examples here) along with the AngularJS wrapper.

Using MomentJS you can define your format easily.


If you want to look more into it, please refer to their documentation.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.