Time Ago Implementation in PHP/LARAVEL
I am CS Student currently perusing my bachelor degree. I love coding and implementing new logics. Aside from that I'm also a hardware lover and has great interest in IOT.
Search for a command to run...
I am CS Student currently perusing my bachelor degree. I love coding and implementing new logics. Aside from that I'm also a hardware lover and has great interest in IOT.
No comments yet. Be the first to comment.
Create a .htaccess in the root of the directory and append this line anywhere in the file. AddHandler application/x-httpd-alt-php74___lsphp .php Here 74 represents PHP version 7.4. If we want 8.1, it would be 81.
We are going to create a local domain like app.local, Create a self-signed wildcard certificate which will works for subdomains as well and point the domain to a locally running site. Generate a self signed certificate https://www.brainbytez.nl/tutor...
GIT_COMMITTER_DATE="Sun Jul 16 14:00 2023 +0545" git commit --amend --date="Sun Jul 16 14:00 2023 +0545"
mkdir output && for file in *.heic; do heif-convert -q 100 "$file" "output/${file/%.heic/.jpg}"; done mkdir -p output && for file in *; do [[ $file == *.heic ]] && heif-convert -q 100 "$file" "output/${file/%.heic/.jpg}" || cp "$file" output/; done
https://dev.to/cloudx/how-to-use-puppeteer-inside-a-docker-container-568c Dockerfile FROM node:slim # We don't need the standalone Chromium ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true # Install Google Chrome Stable and fonts # Note: this installs the...
Original Post Url : https://www.w3schools.in/php/examples/time-ago-function
PHP Time Ago functionality is used to display time in a different format.
It takes the timestamp as input and subtracts it with the current timestamp. Then it compares the remaining date with a predefined set of rules which determine the month, day, minute, and even year. Then it calculates time difference by using a predefined set of rules which determine the second, minute, hour, day, month, and year.
function get_time_ago( $time )
{
$time_difference = time() - strtotime($time);
if( $time_difference < 1 ) { return 'less than 1 second ago'; }
$condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach( $condition as $secs => $str )
{
$d = $time_difference / $secs;
if( $d >= 1 )
{
$t = round( $d );
return 'about ' . $t . ' ' . $str . ( $t > 1 ? 's' : '' ) . ' ago';
}
}
}
echo get_time_ago( time()-5 ).'<br>';
//about 5 seconds ago
echo get_time_ago( time()-60 ).'<br>';
//about 1 minute ago
echo get_time_ago( time()-3600 ).'<br>';
//about 1 hour ago
echo get_time_ago( time()-86400 ).'<br>';
//about 1 day ago
echo get_time_ago( time()-2592000 ).'<br>';
//about 1 month ago
echo get_time_ago( time()-31104000 ).'<br>';
//about 1 year ago
.
.
.
echo get_time_ago( strtotime("2013-12-01") );
//about 2 years ago