Created
May 22, 2022 12:37
-
-
Save dab2020/e0e02b3ee52d1ac3d5c91988dd36be36 to your computer and use it in GitHub Desktop.
Finds the ammount of time since a article was published in Vanilla Java Script and also rounds it up into a whole number
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
<script type = "text/javascript" > | |
// By @dab2020 on github | |
// One month Time in ms (milliseconds) | |
var one_month = 1000 * 60 * 60 * 24 * 30 | |
// To set present_dates to two variables | |
var present_date = new Date(); | |
// 0-11 is Month in JavaScript | |
var publish_day = new Date(2021, 1, 1) | |
// To Calculate the result in milliseconds and then converting into months | |
var Result = Math.round(present_date.getTime() - publish_day.getTime()) / (one_month); | |
// To remove the decimals from the (Result) months value | |
var Final_Result = Result.toFixed(0); | |
//To display the final_result value | |
document.write("Published " | |
+ Final_Result | |
+ " months ago"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment