How to use 'javascript time ago' in JavaScript

Every line of 'javascript time ago' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
8export function timeAgo (time) {
9 const between = Date.now() / 1000 - Number(time)
10 if (between < 3600) {
11 return pluralize(~~(between / 60), ' minute')
12 } else if (between < 86400) {
13 return pluralize(~~(between / 3600), ' hour')
14 } else {
15 return pluralize(~~(between / 86400), ' day')
16 }
17}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets