javascript - How do I convert JSON string date to a custom format date? -


hi know how convert json string date comes response format "8/24/2016". made datefilter.js bit didn't work out expected here's tried.

here's datefilter.js (actually didn't work. error: data recursion)

(function () {      angular         .module('myapp')         .filter('date', function ($filter) {              return function (input) {                  if (input == null) {                      return "";                     }                 var _date = $filter('date')(new date(input), 'dd/mm/yyyy');                  return _date.touppercase();             };         }); })(); 

here's how json service (the code not complete since want show how did response.)

function getempdetails(successcallback, failcallback) {              var req = {                 method: 'get',                 url: 'http://localhost:2222/api/getemployees/getemployeedetails',                 headers: {                     'content-type': 'application/json'                 }             }             $http(req).then(successcallback, failcallback);         } 

the controller.js

(function initcontroller() {      employeeservice.getempdetails(function (res) {         $scope.employeedetails = json.parse(res.data);          //console.log(res.data);          }     }); 

and applying filter html.

<table id="basic-datatables" class="table table-striped table-bordered" cellspacing="0" width="100">    <thead style="text-align:match-parent">        <tr>            <th rowspan="1" colspan="1" style="width:195px">first name</th>            <th rowspan="1" colspan="1" style="width:195px">last name</th>            <th rowspan="1" colspan="1" style="width:200px">date of birth</th>            <th rowspan="1" colspan="1" style="width:100px">gender</th>            <th rowspan="1" colspan="1" style="width:200px">email</th>            <th rowspan="1" colspan="1" style="width:100px">mobile</th>            <th rowspan="1" colspan="1" style="width:190px">designation</th>            <th rowspan="1" colspan="1" style="width:200px">date of join</th>            <th rowspan="1" colspan="1" style="width:195px">nic</th>            <th rowspan="1" colspan="1" style="width:100px">dept. name</th>        </tr>    </thead>    <tbody>        <tr ng-repeat="emp in employeedetails.slice(((currentpage-1)*itemsperpage),((currentpage)*itemsperpage))" style="text-align:center">            <td>{{emp.fname}}</td>            <td>{{emp.lname}}</td>            <td>{{emp.dob | date}}</td> //applying filter            <td>{{emp.gender}}</td>            <td>{{emp.email}}</td>            <td>{{emp.mobile_no}}</td>            <td>{{emp.designation}}</td>            <td>{{emp.date_of_join | date}}</td> //applying filter            <td>{{emp.nic}}</td>            <td>{{emp.department_name}}</td>        </tr>    </tbody> </table>  

so how there's other way of conversion.

final note: right without filter: 7/25/2016 12:00:00 want convert 7/25/2016

help appreciated.

just try code. think solves problem:

<td>{{emp.dob | dateformat}}</td> 

angular filter :

.filter('dateformat', function() {     return function(dt) {         var dt = new date(dt);         return (dt.getmonth()+1)+'/'+dt.getdate()+'/'+dt.getfullyear();     };   }) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -