Pergunta

I wonder how can I keep the date of publication always up, as do the Twitter, Facebook sites using a Knockout lib. Follow the example:enter image description here

The update is "taken" as time passes.

Sorry if there is already something about it, I'm not sure what that's called, much less how to do a search on Google, I did not return me the expected results.

Foi útil?

Solução

there you go, using SugarJs for date parsing

var updateInterval = 5 * 1000; // update every 5 seconds
var postDate = new Date();     // this supposed to be the post date

function model() {
    var self = this;
    this.relativeTime = ko.observable();
    setInterval(function() {
        self.relativeTime( Date.create( postDate ).relative() );
    }, updateInterval);
}

ko.applyBindings( new model() );

JsFiddle Demo

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top