Created
November 2, 2022 20:36
-
-
Save Klerith/f5cb31404fef4bad8160ce4eac5318b2 to your computer and use it in GitHub Desktop.
Fecha de creación humana
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias!!