This is a flexible function for making time periods readable.
It allows for the conversion of an integer number of seconds into a readable string. For example, “121” into “2 minutes, 1 second”.
The $use parameter allows you to define which time periods should be used (default is null, which is all time periods). The $zeros parameter allows you to set whether zero time periods should be displayed, e.g. “0 years, 0 months” (defaults to false).
Let’s have a look at some examples:
This would produce the following output:
3 years, 2 months, 19 hours, 22 minutes, 16 seconds
3 years, 2 months, 0 weeks, 0 days, 19 hours, 22 minutes, 16 seconds
3 years, 2 months
1157 days