Date_diff calculation & amp; quot; Operation Time & amp; quot; interval from & amp; quot; current Time & amp; quot;
There are many similar comments in many blogs. comments: xx minutes and xx seconds show the comment for a long time. today, I made a comment using php's date_diff.
- Function get_Pass_Date ($ ymdhms1, $ ymdhms2 ){
- $ Datetime1 = date_create ("$ ymdhms1 ");
- $ Datetime2 = date_create ("$ ymdhms2 ");
- $ Interval = date_diff ($ datetime1, $ datetime2 );
- $ Psdate = null;
- If ($ interval-> y> 0 ){
- $ Psdate = $ interval-> format ('% y year % m month % d Day % h hour % I minute % S ');
- } Else if ($ interval-> m> 0 ){
- $ Psdate = $ interval-> format ('% m month % d Day % h hour % I minute % s second ');
- } Else if ($ interval-> d> 0 ){
- $ Psdate = $ interval-> format ('% d day % h hour % I minute % S ');
- } Else if ($ interval-> h> 0 ){
- $ Psdate = $ interval-> format ('% h % I % s s ');
- } Else if ($ interval-> I> 0 ){
- $ Psdate = $ interval-> format ('% I % S ');
- } Else {
- $ Psdate = $ interval-> format ('% s ');
- }
- Return $ psdate;
- }
|