javascript - Date conversion using Ractive.js -


how convert epoch time value returned json end point time string "tue 19 jan 11:14:07 sgt 2038"?

var ractive = new ractive({    el: '#container',      template: '#template',      data: {      lastupdated: 2147483647    }  });
<script src="http://cdn.ractivejs.org/latest/ractive.js"></script>  <pre>$ date --date='@2147483647'	  tue 19 jan 11:14:07 sgt 2038  </pre>    <div id='container'></div>  <script id='template' type='text/ractive'>    <h1>time: {{date(lastupdated)}}</h1>  </script>

i don't want use additional libraries moment.js. thanks!

ractive doesn't have opinion how format dates, can add custom formatter data object:

var ractive = new ractive({   el: '#container',   template: '<h1>time: {{formatdate(lastupdated)}}</h1>',   data: {     lastupdated: 2147483647,     formatdate: function ( date ) {       // formatting code goes here...     }   } }); 

whenever lastupdated changes, formatter called again.


Comments