0
<li ng-repeat="poll in polls">
    <span>{{poll._id.getTimestamp() | date:'shortTime'}}</span>
</li>

Each poll object has an ObjectId like this one: "5629a520f7ca231816cd373e" How do I convert this to a timestamp within an AngularJS template? The above code is not producing any output.

Yogeshree Koyani
  • 1,649
  • 10
  • 19
Apollo
  • 8,874
  • 32
  • 104
  • 192
  • Have you looked at http://stackoverflow.com/questions/6452021/getting-timestamp-from-mongodb-id – kensplanet Oct 23 '15 at 03:31
  • @KennethJohn Yeah I tried this approach, as you can probably tell from my code snippet in the question. This doesn't seem to work though. I'm not quite sure why... – Apollo Oct 23 '15 at 03:37
  • If your poll._id = "5629a520f7ca231816cd373e", then what is the getTimestamp() method. Have you manually defined this method? – kensplanet Oct 23 '15 at 03:43
  • @KennethJohn No I haven't defined the method. I tried `poll._id..substring(0,8)` but I don't think that's how MongoDB saves the date inside the id because this produced weird results as well (letters in the first 8 characters for some strings) – Apollo Oct 23 '15 at 03:45
  • `var timestamp ="5629a520f7ca231816cd373e".toString().substring(0,8);` undefined var date = new Date( parseInt( timestamp, 16 ) * 1000 ); undefined date Thu Oct 22 2015 23:10:24 GMT-0400 (Eastern Daylight Time) – kensplanet Oct 23 '15 at 03:49
  • I just happened to convert it into a timestamp and it did appear to be a proper one - **Thu Oct 22 2015 23:10:24 GMT-0400 (Eastern Daylight Time)** – kensplanet Oct 23 '15 at 03:51
  • @KennethJohn What about this one then: `5629a520f7ca231816cd373e` – Apollo Oct 23 '15 at 03:52
  • Well, that's the one which I converted. Can you check this fiddle - http://jsfiddle.net/kensplanet/z8t2tk0z/ – kensplanet Oct 23 '15 at 03:57

0 Answers0