1

Could anyone please suggest me how to convert date from this 1387843200000 format into this 23rd April,2017 inside my controller? I tried with the following code

duedate=1387843200000
date = $filter('date')(duedate, "dd MMM, yyyy");

It gives me the date like 23 Apr,2017. But I want like 23rd April,2017

2 Answers 2

1

Convert 1387843200000 to be a javascript date and bind using angularJs like :

var app = angular.module("app", []).controller("ctrl", function($scope) { 

  $scope.changedDate= new Date(1387843200000);

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

<body ng-app="app">
  <div ng-controller = "ctrl">
    <span>{{changedDate | date : 'medium'}}</span>
  </div>
</body>

Sign up to request clarification or add additional context in comments.

Comments

0

You can format the miliseconds to date first by

var miliseconds = 1387843200000;
var date = new Date(miliseconds);

and then you can use momentjs for format the date based on what you like. If you want change based on your question, then just do something like this

date = moment(date).format('Do MMM, YYYY')

or if you want to know more the format, you can open momentjs website

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.