Skip to content

Instantly share code, notes, and snippets.

@angelcgar
Forked from Klerith/time-since.ts
Created October 31, 2024 20:02
Show Gist options
  • Save angelcgar/722313bc530ed683c20d2e3f8edf11e3 to your computer and use it in GitHub Desktop.
Save angelcgar/722313bc530ed683c20d2e3f8edf11e3 to your computer and use it in GitHub Desktop.
Fecha de creación humana
export const timeSince = ( date: string ) => {
const baseDate = new Date(date)
const seconds = Math.floor(( new Date().getTime() - baseDate.getTime() ) / 1000);
let 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";
}
@angelcgar
Copy link
Author

Pues ahora ya es mio, creo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment