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 :: angular wait all subscriptions 
Javascript :: addition of two matrix in javascript 
Javascript :: how to check all elements in array includes in another array javascript 
Javascript :: how to validate file type in jquery 
Javascript :: javascript currency number format indonesia 
Javascript :: how to add toaster in angular 9 
Javascript :: react background image opacity 
Javascript :: how to numbers by checked in checkbox in javascript 
Javascript :: js get random from array 
Javascript :: vue js copy text to clipboard 
Javascript :: is object js 
Javascript :: assign class to element javascript 
Javascript :: list all functions in an object js 
Javascript :: access session data from ejs view 
Javascript :: javascript is not null 
Javascript :: createelement with id javascript 
Javascript :: jquery checkvalidity 
Javascript :: how to get the timestamp in javascript 
Javascript :: how to update the react version in next js app 
Javascript :: js includes 
Javascript :: how to delete a reply in discord.js 
Javascript :: dynamic folder import javascript 
Javascript :: how to check all values of an array are equal or not in javascript 
Javascript :: how to remove duplicates in array in javascript 
Javascript :: apply eventlistener to iframe 
Javascript :: hex string to buffer nodejs 
Javascript :: creating array of objects usinng reduce js 
Javascript :: javascript replace all spaces 
Javascript :: Fibonacci Recursive in js 
Javascript :: app.use 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =