0
Hello,
Through the function below, I intend to display the last seen.
However, it is showing the last month, instead of showing the current month.
For example, I am sending the current date but is returning month 2.
let ret = mDate('2019-03-12 17:41:19').lastSeenFormat()
console.log('last seen ' + ret);
alert('last seen ' + ret);
// code
function mDate(dateString){
let date = dateString ? new Date(dateString) : new Date();
let dualize = (x) => x < 10 ? "0" + x : x;
let getTime = () => dualize(date.getHours()) + ":" + dualize(date.getMinutes());
let getDate = () => dualize(date.getDate()) + "/" + dualize(date.getMonth()) + "/" + dualize(date.getFullYear());
return {
subtract: (otherDateString) => {
return date - new Date(otherDateString);
},
lastSeenFormat: () => {
let dateDiff = Math.round(new Date() - date) / (1000 * 60 * 60 * 24);
let value = (dateDiff === 0) ? "today" : (dateDiff === 1) ? "yesterday" : getDate();
return value + " at " + getTime();
},
chatListFormat: () => {
let dateDiff = Math.round((new Date() - date) / (1000 * 60 * 60 * 24));
if (dateDiff === 0) {
return getTime();
} else if (dateDiff === 1) {
return "Yesterday";
} else {
return getDate();
}
},
getDate: () => {
return getDate();
},
getTime: () => {
return getTime();
},
toString:() => {
return date.toString().substr(4, 20);
},
};
};
This would not be the solution
getMonth() + 1
so I wouldn’t show the stringtoday
.– Wagner Fillio
Yes, it’s the simplest way.
– Júlio Neto