I have a chat, and I'm appending a timestamp for when comment a is made.
This is how Im doing it using Pusher and Laravel 5.2:
channel.bind('App\\Events\\MessageSent', function(data){
console.log(data);
$('#chat-box-message').empty(html);
for (var i = 0; i< data.length; i++) {
for (var key in data) { //empty the div for append does not repeat
var obj = data[key];
for (var prop in obj) {
$('#chat-box-message').append(
'<div class="comment">'+
' +obj[prop]['gamertag']+
'<div class="metadata">'+
+ moment(obj[prop]['created_at']).format('h:mm:ss a') +
'</div>'
);
}
}
}
});
When I type something in the chat, this is the result I get from the other users screen.
How can I adjust the time to be my current time, which was 8:26 PM when that comment was made.
I'm using the moment JS Library.
Or even better yet, show relative time, like say the comment was posted 5 min ago.