JS implementation a few minutes ago, a few hours ago, a few days ago, and a few minutes later, a few hours later, a few days before and after
/ * *
*Compare the incoming timestamp with the current time, and calculate the time before, hours, days, minutes, hours, and days
*UNIX time stamp to be calculated, reserved to seconds
* * /
function getDateTimeFormat(unixtime) {
var currTime = Date.parse(new Date());;
var time = ((parseInt(currTime)/1000) - parseInt(unixtime)) ;
if(time > 0 ){
//Less than one minute
if (time < 60) {
Return "wait";
}
//Seconds to minutes
var minuies = time / 60;
if (minuies < 60) {
Return math. Floor (minutes) + "in minutes";
}
//Second to hour
var hours = time / 3600;
if (hours < 24) {
Return math. Floor (hours) + "after hours";
}
//Seconds to days
var days = time / 3600 / 24;
if (days < 30) {
Return math. Floor (days) + day after;
}
/ / sec
var months = time / 3600 / 24 / 30;
if (months < 12) {
Return math. Floor (months) + "after month";
}
/ / second year
var years = time / 3600 / 24 / 30 / 12;
Return math. Floor (years) + "after year";
}else{
time = Math.abs(time);
//Less than one minute
if (time < 60) {
Return "just";
}
//Seconds to minutes
var minuies = time / 60;
if (minuies < 60) {
Return math. Floor (minutes) + "minutes ago";
}
//Second to hour
var hours = time / 3600;
if (hours < 24) {
Return math. Floor (hours) + "hours ago";
}
//Seconds to days
var days = time / 3600 / 24;
if (days < 30) {
Return math. Floor (days) + "days ago";
}
/ / sec
var months = time / 3600 / 24 / 30;
if (months < 12) {
Return math. Floor (months) + "before the month";
}
/ / second year
var years = time / 3600 / 24 / 30 / 12;
Return math. Floor (years) + "years ago";
}
}
JS implementation a few minutes ago, a few hours ago, a few days ago, and a few minutes later, a few hours later, a few days before and after