Horje
is date 1 day ago javascript Code Example
one year ago javascript date
var startDate = new Date();
    startDate.setFullYear(startDate.getFullYear() - 1);
how to show 1 day ago in javascript
function timeSince(date) {

  var seconds = Math.floor((new Date() - date) / 1000);

  var interval = seconds / 31536000;

  if (interval > 1) {
    return Math.floor(interval) + " years";
  }
  interval = seconds / 2592000;
  if (interval > 1) {
    return Math.floor(interval) + " months";
  }
  interval = seconds / 86400;
  if (interval > 1) {
    return Math.floor(interval) + " days";
  }
  interval = seconds / 3600;
  if (interval > 1) {
    return Math.floor(interval) + " hours";
  }
  interval = seconds / 60;
  if (interval > 1) {
    return Math.floor(interval) + " minutes";
  }
  return Math.floor(seconds) + " seconds";
}
var aDay = 24*60*60*1000;
console.log(timeSince(new Date(Date.now()-aDay)));
console.log(timeSince(new Date(Date.now()-aDay*2)));
is date 1 day ago javascript
function daysSinceGivenDate (date) {
  const dateInSeconds = Math.floor((new Date().valueOf() - date.valueOf()) / 1000);
  const oneDayInSeconds = 86400;

  return (dateInSeconds / oneDayInSeconds) | 0; // casted to int
};

console.log(daysSinceGivenDate(new Date())); // 0
console.log(daysSinceGivenDate(new Date("January 1, 2022 03:24:00"))); // relative...




Javascript

Related
how to export a class in node js Code Example how to export a class in node js Code Example
node js event emitter Code Example node js event emitter Code Example
convert date dd/mm/yyyy to date object js Code Example convert date dd/mm/yyyy to date object js Code Example
VM1188:1 Uncaught TypeError: $ is not a function at <anonymous>:1:1 Code Example VM1188:1 Uncaught TypeError: $ is not a function at <anonymous>:1:1 Code Example
get scroll position jquery Code Example get scroll position jquery Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7