Display time elapsed using php

I want to show the time elapsed since the time was published for a blog or similar, I use php and I store the time sent as a unix timestamp, but I can not live for me to understand how to show the time from the moment it posting using a saved timestamp.

+4
source share
2 answers

If, for example, your marked timestamp is:

1289735677 

You can also get the current timestamp using time() , for example.

Then you can take your marked timestamp from the current one:

 time() - 1289735677 

This way you get the elapsed seconds. Now you can change them to a human-readable format.

See examples of how you can convert seconds to human-readable format:

+6
source

If your PHP => 5.3.0, you can use the DateTime :: diff method.

+2
source

All Articles