I have a post action method which properly saves data into database along with date in utc date format. Now, i have a get method which fetches all the data from database in proper format like this:
public JsonResult GetPosts()
{
var ret = (from post in db.Posts.ToList()
orderby post.PostedDate descending
select new
{
Message = post.Message,
PostedBy = post.PostedBy,
PostedByName = post.ApplicationUser.UserName,
PostedByAvatar = _GenerateAvatarUrlForUser(post.PostedBy),
PostedDate = post.PostedDate,
PostId = post.PostId,
});
return Json(ret, JsonRequestBehavior.AllowGet);
}
now, i have added getTimeAgo plugin from nuget packages and added to script folder. In my Scripts folder, i have a wallpost.js file which contains client side models for updating model and client side view model for updating UI automatically. here, i have a getTimeAgo function to get fuzzy time stamps from utc datetime. It is something like this:
function getTimeAgo(varDate) {
if (varDate) {
return $.timeago(varDate.toString().slice(-1) == 'Z' ? varDate : varDate + 'Z');
}
else {
return '';
}
} But on the view page, its simply displaying NaNyearsAgo.As i have said earlier, date is saved in proper format in database but i am unable to convert utc date time to fuzzy time stamps. I have uploaded my entire wallpost.js file here for increasing brevity.http://pastebin.com/VVUuMScL On my View Page, I am showing post with user's image like this:
<ul id="msgHolder" data-bind="foreach: posts">
<li class="postHolder">
<img data-bind="attr: { src: PostedByAvatar }" width="150" height="200">
<p><a data-bind="text: PostedByName"></a>: <span data-bind=" html: Message"></span></p>
<div class="postFooter">
<span class="timeago" data-bind="text: PostedDate"></span> <a class="linkComment" href="#" data-bind=" click: toggleComment">Comment</a>
</div>
</li>
Please suggest me what is going wrong.