Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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)));
Comment

1 day ago javascript

function daysSinceGivenDate(date: Date) {
    const dateInSeconds = Math.floor((new Date().valueOf() - new Date(date).valueOf()) / 1000);
    const oneDayInSeconds = 86400;

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

console.log(daysSinceGivenDate(new Date())); // 0
Comment

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...
Comment

PREVIOUS NEXT
Code Example
Javascript :: ordenar un array de mayor a menor 
Javascript :: react build size 
Javascript :: shadow class angular 
Javascript :: js array push 
Javascript :: node fetch response body 
Javascript :: change the color of toast toastr js 
Javascript :: javascript array sorting 
Javascript :: @angular-devkit/build-angular <error 
Javascript :: alpine js open outside div 
Javascript :: js if not undefined or null 
Javascript :: material ui react card 
Javascript :: datatble tab bootstrap 4 
Javascript :: random key generator 
Javascript :: npm install --save react-draft-wysiwyg draft-js react-draft-wysiwyg-a 
Javascript :: expo dependencies 
Javascript :: electron js web reference to use node 
Javascript :: jest express testing 
Javascript :: js compare objects 
Javascript :: get file css code with javascript 
Javascript :: javascript forEach() method 
Javascript :: get index of first number in string javascript 
Javascript :: axios error network error 
Javascript :: what is a block in javascript 
Javascript :: momentum 
Javascript :: angular date pipi locale 
Javascript :: indefOf 
Javascript :: javascript regex all matches match 
Javascript :: How to Use the replace() String Method in javascript 
Javascript :: access to nested properties on javascript using property names 
Javascript :: create a react app 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =