0

{{}} is the tag i am using in my html. when i get date from database it is showing Date(1453228200000) in milliseconds for date 1/20/2016. how to solve it.

Anirudh
  • 558
  • 1
  • 6
  • 22

4 Answers4

1

var date = new Date(parseInt($scope.data.Last_recharge_date)); Before this you have to remove the substring "Date(" and ")" and pass only milliseconds number then only you will get. try to remove the string

Uday
  • 149
  • 1
  • 5
  • this won't parse what OP is sending from server by itself – charlietfl Jan 22 '16 at 05:09
  • http://stackoverflow.com/questions/17925020/angularjs-convert-tag-value-unix-time-to-human-readable-time check this here they answered same – Uday Jan 22 '16 at 05:13
  • inside {{item.date * 1000 | date:'yyyy-MM-dd HH:mm:ss Z'}} try to use like this – Uday Jan 22 '16 at 05:16
  • Do you referred what charlietfl given link ? – Uday Jan 22 '16 at 05:29
  • they used var date = new Date(parseInt(1453228200000)); – Uday Jan 22 '16 at 05:30
  • var date = new Date(parseInt($scope.data.Last_recharge_date)); Before this you have to remove the substring "Date(" and ")" and pass only milliseconds number then only you will get. try to remove the string – Uday Jan 22 '16 at 06:34
  • thank's bro its working after parsing and removing the Date and () – Anirudh Jan 22 '16 at 08:26
0

All you need is new Date(1453228200000) and then apply any filters/format filter you need

Taj Ahmed
  • 895
  • 11
  • 19
  • I did this in js var date = new Date(parseInt($scope.data.Last_recharge_date)); $scope.data.Last_recharge_date = date; – Anirudh Jan 22 '16 at 06:10
0

Multiple ways you can convert to the date format.

  1. Create a custom filter. Add the code in custom filter new Date(1453228200000).toUTCString() and It will return "Tue, 19 Jan 2016 18:30:00 GMT" .

    Jsfiddle Custom Filter

  2. Use the same code to convert to date format on the service level(after fetching data form server).

Nidhin T T
  • 298
  • 2
  • 5
  • 15
0
<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the milliseconds of a given date-time.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var d = new Date(1453228200000);
    var n = d.toString();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

There are lot of other functions which can be used http://www.w3schools.com/jsref/jsref_obj_date.asp.

Mahesh Malpani
  • 1,782
  • 16
  • 27