Converts datetime to Chinese. The following is a method for converting datetime to adult, month, day, hour, minute, and second. For more information, see. The following is a conversion of datetime date and time to adult \ ', \ 'months \', \ 'Day \ ', \ 'hour \', \ 'specificity \ ', \ 'seconds \' to display. if you need it, refer to it.
The following example shows how to convert datetime to adult, month, day, hour, specificity, and second, for more information, see.
/**
* Friendly date and time
*
* @ Param DateTime $ datetime date and time
* @ Param int $ size precise to the number of digits
* @ Throws InvalidArgumentException
* @ Return string
*/
Function friendly_date ($ datetime, $ size = 1)
{
If (is_int ($ datetime )){
$ Datetime = new DateTime ($ datetime );
}
If (! ($ Datetime instanceof DateTime )){
Throw new InvalidArgumentException ('invalid "DateTime" object ');
}
$ Now = new DateTime ();
$ Interval = $ now-> diff ($ datetime );
$ IntervalData = array (
$ Interval-> y, $ interval-> m, $ interval-> d,
$ Interval-> h, $ interval-> I, $ interval-> s,
);
$ IntervalFormat = array ('year', 'month', 'day', 'Hourly ', 'specificity', 'second ');
Foreach ($ intervalData as $ index => $ value ){
If ($ value ){
$ IntervalData [$ index] = $ value. $ intervalFormat [$ index];
} Else {
Unset ($ intervalData [$ index]);
Unset ($ intervalFormat [$ index]);
}
}
Return implode ('', array_slice ($ intervalData, 0, $ size ));
}
Expiration, \ 'months \ ', \ 'Day \', \ 'hour \ ', \ 'classification \', \ 'second \ 'to display, for more information, see. The following is...