How to make a reasonable date after time
I am making a web app and I need to display the t开发者_C百科ime when something was sent. Now, I want it to start like "2:30 PM", and then after the day has passed it would change to "July 26", how could I do this in PHP?
The code is the same as you'd describe the flow in English: "if the time is less than a day ago, show 2:30PM, otherwise show July 26".
if (time() - strtotime($time_sent) < 24*60*60) {
echo date('g:i A', strtotime($time_sent));
} else {
echo date('F j', strtotime($time_sent));
}
Not PHP - but I use the timeago jquery plugin to accomplish this. This way, you store and retrieve one date and time, but it is displayed accordingly as time passes.
精彩评论