Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

time ago function web

const intervals = [
  { label: 'year', seconds: 31536000 },
  { label: 'month', seconds: 2592000 },
  { label: 'day', seconds: 86400 },
  { label: 'hour', seconds: 3600 },
  { label: 'minute', seconds: 60 },
  { label: 'second', seconds: 1 }
];

function timeSince(date) {
  const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
  const interval = intervals.find(i => i.seconds < seconds);
  const count = Math.floor(seconds / interval.seconds);
  return `${count} ${interval.label}${count !== 1 ? 's' : ''} ago`;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to only register one click on nested component and not parent component in react js 
Javascript :: useEffect not working array changes 
Javascript :: browser extensions settings page 
Javascript :: convert js to typescript online 
Javascript :: node.js vds connection was aborted 
Javascript :: how to disable search box and placeholder by putting some conditions using js 
Javascript :: https - node load testing- 
Javascript :: dummy servers using nodejs 
Javascript :: enum in javascript es6 
Javascript :: Nested objects and files 
Javascript :: modal in react 
Javascript :: Mapping an Array to Elements with v-for 
Javascript :: useeffrc 
Javascript :: event on trible click in js 
Javascript :: javascript firebase kicks out current user 
Javascript :: Java compile script 
Javascript :: redux counter 
Javascript :: New year chaos solution 
Javascript :: remove json parameter 
Javascript :: loopover iterate elements by name js 
Javascript :: // Write a function that takes two numbers (a and b) as argument // Sum a and b // Return the result 
Javascript :: how to poll every n seconds in react js 
Javascript :: child to perent data transfer in angular 
Javascript :: Full form of BOM in Javascript is 
Javascript :: split name js 
Javascript :: how take a item from object javascript 
Javascript :: Tow sums 
Javascript :: angular reuse component with different data 
Javascript :: backbone.js validation 
Javascript :: Include Id In Backbone 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =