Possible Duplicate:
How do I calculate relative time?
I want to format dates on my social web app much like Digg.com and other sites do. There, you see very friendly dates, such as:
Before I wrap my head around creating such a thing, does anyone know of any ready-to-go script for this where I simply insert a datestamp and a friendly date text is given based on how it related to the current time?
PS: I need this in PHP, but pseudo-code or any other language is fine too.
const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.
The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.
MM/DD/YY. Month-Day-Year with leading zeros (02/17/2009) 2. DD/MM/YY. Day-Month-Year with leading zeros (17/02/2009)
This is a duplicate of this question. It has a flurry of code samples on how to accomplish this, in addition to the code this very site uses. I glanced at it and there seems to be a PHP implementation posted there too.
In addition to all this, if are you using jQuery you can do this client-side with something like the timeago plugin. It has the advantage of updating the text as time passes so if you load a page and it says "posted 5 minutes ago" and look again 5 minutes later, it says "posted 10 minutes ago"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With