๐ Friendly Format
7/28/26Less than 1 minute
๐ Friendly Format
Tips
It is generally used on social platforms, comments, forums, etc
toFriendly()
Returns a friendly date format, such as N seconds ago or in N seconds
Parameters
| Parameter | Introduction | Require |
|---|---|---|
| time | Any type of string time or timestamp | required |
| lang | Language: zh for Chinese, en for English | Optional, the default value is zh |
Return Values
Friendly date format
Past dates return text such as 2ๅฐๆถๅ or 2 hours ago. Future dates return 2ๅฐๆถๅ or in 2 hours. A date in the same second returns ๅๅ or just now, depending on the selected language.
Example code
/* Convert to a friendly date format */
TimeHelper::toFriendly('2022-3-2 10:15:33');
// 3ๅคฉๅ
/* Convert to a friendly date format */
TimeHelper::toFriendly(1646186290, 'en');
// 6 hours ago
/* Convert a future time to a friendly date format */
TimeHelper::toFriendly(time() + 7500, 'en');
// in 2 hours
/* Convert a future time to a friendly date format (Chinese) */
TimeHelper::toFriendly(time() + 7500);
// 2ๅฐๆถๅ