Window.onload = function () {
var show_times = $ (". Times span");
for (Var i=0;i<show_times.length;i++) {
var datestr = show_times[i].innerhtml;
var datetimestamp = Date.parse (Datestr.replace (/-/gi, "/"));
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var month = day * 30;
Get current time
var now = new Date (). GetTime ();
var diffvalue = Now-datetimestamp;
var monthc =diffvalue/month;
var weekc =diffvalue/(7*day);
var dayc =diffvalue/day;
var hourc =diffvalue/hour;
var MinC =diffvalue/minute;
if (monthc>=1) {
show_times[i].innerhtml = Datestr;
}
else if (weekc>=1) {
result= "Posted in" + parseint (WEEKC) + "weeks ago";
show_times[i].innerhtml = result;
}
else if (dayc>=1) {
result= "Posted in" + parseint (DAYC) + "days ago";
show_times[i].innerhtml = result;
}
else if (hourc>=1) {
result= "Posted in" + parseint (HOURC) + "hours ago";
show_times[i].innerhtml = result;
}
else if (minc>=1) {
result= "Posted in" + parseint (MinC) + "Minutes ago";
show_times[i].innerhtml = result;
}else{
Result= "published in 1 minutes";
show_times[i].innerhtml = result;
}
}
}
JS display time difference a few minutes ago, a few hours ago, a few weeks ago.