Reputation: 864
Guys I am getting date through ajax call in my ASP.net mvc application. Now the date I am getting is in the format of 2014-06-09T17:38:55
however I want to display it in three formats:
06/09/2014 05:38:55 PM
three hours ago
or Yesterday
style (used by facebook)06/09/2014
Basically I have a hidden input field in my view which gets the Date from ajax call. Now I am doing something like this :
<input id="hiddenLastAlertDate" type="hidden" value="values.CreationDate" />
In my script section, I have a function in which I am doing something like this:
var datefield = document.getElementById("hiddenLastAlertDate").value;
formattedDate = moment(datefield).format('L'); //for getting the date part only
Upon running the application,formattedDate shows up as undefined. Why is that? I think I was unable to follow the moment.js documentation. How can I use moment.js to get this formatted result ?
Upvotes: 0
Views: 1805
Reputation: 999
moment("20140618 08:00", "YYYYMMDD hh:mm").fromNow();
will return 2 hours ago
moment("20140617", "YYYYMMDD").fromNow();
will return a day ago
moment().format('DD/MM/YYYY h:mm:ss A');
will return 18/06/2014 9:42:24 AM
Upvotes: 2